View Javadoc
1   package org.djutils.data.serialization;
2   
3   /**
4    * CharacterSerializer (de)serializes Character objects.
5    * <p>
6    * Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS License</a>.
8    * </p>
9    * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
10   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
11   * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
12   */
13  public class CharacterSerializer implements SpecificTextSerializer<Character>
14  {
15      @Override
16      public String serialize(final Character value, final String unit)
17      {
18          return value == null ? null : String.valueOf(value.charValue());
19      }
20  
21      @Override
22      public Character deserialize(final Class<Character> type, final String text, final String unit)
23      {
24          return (text == null || text.isEmpty()) ? null : text.charAt(0);
25      }
26  
27  }