Class WicaDoubleSerializer

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Double>
ch.psi.wica.infrastructure.channel.WicaDoubleSerializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable

@Immutable class WicaDoubleSerializer extends com.fasterxml.jackson.databind.JsonSerializer<Double>
Provides a means of serializing objects of type Double in such a way that a configurable number of digits appear after the decimal point.

This class works in conjunction with Jackson library module class with whom it must be registered.

  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

    com.fasterxml.jackson.databind.JsonSerializer.None
  • Constructor Summary

    Constructors
    Constructor
    Description
    WicaDoubleSerializer(int numericScale)
    Constructs a new custom serializer for doubles.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    serialize(Double value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers)
    Serialize the Double.
    (package private) static void
    serializeDouble(Double value, com.fasterxml.jackson.core.JsonGenerator gen, int numericScale)
     

    Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

    acceptJsonFormatVisitor, getDelegatee, handledType, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WicaDoubleSerializer

      WicaDoubleSerializer(int numericScale)
      Constructs a new custom serializer for doubles.

      The serializer generates a string representation with the specified numeric scale (that's to say with the specified number of digits after the decimal point).

      Where the numeric scale forces rounding, then a RoundingMode.HALF_UP strategy is implemented.

      The JSON generator associated with this serializer can be configured to determine whether this serializer writes special values NaN and Infinity as numbers or strings.

      Parameters:
      numericScale - a positive number specifying the number of digits to appear after the decimal point in the serialized representation.
      Throws:
      IllegalArgumentException - if the requested numeric scale is negative.
  • Method Details

    • serializeDouble

      static void serializeDouble(Double value, com.fasterxml.jackson.core.JsonGenerator gen, int numericScale) throws IOException
      Parameters:
      value - the value to be serialized.
      gen - reference to a Java generator object that provides methods for generating the output string.
      numericScale - a positive number specifying the number of digits to appear after the decimal point in the serialized representation.
      Throws:
      IOException - if something goes wrong.
    • serialize

      public void serialize(Double value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException
      Serialize the Double.
      Specified by:
      serialize in class com.fasterxml.jackson.databind.JsonSerializer<Double>
      Parameters:
      value - the value to be serialized.
      gen - reference to a Java generator object that provides methods for generating the output string.
      serializers - reference to a serializer provider (not needed by this implementation)
      Throws:
      IOException