View Javadoc
1   package org.djutils.data.serialization;
2   
3   /**
4    * BooleanSerializer (de)serializes Boolean objects.
5    * <p>
6    * Copyright (c) 2020-2023 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 BooleanSerializer implements SpecificTextSerializer<Boolean>
14  {
15      /** {@inheritDoc} */
16      @Override
17      public String serialize(final Boolean value, final String unit)
18      {
19          return value == null ? null : value.toString();
20      }
21  
22      /** {@inheritDoc} */
23      @Override
24      public Boolean deserialize(final Class<Boolean> type, final String text, final String unit)
25      {
26          return (text == null || text.isEmpty()) ? null : Boolean.valueOf(text);
27      }
28  
29  }