Class DecimalFloatAdapter

java.lang.Object
jakarta.xml.bind.annotation.adapters.XmlAdapter<String,Float>
de.gurkenlabs.litiengine.environment.tilemap.xml.DecimalFloatAdapter

public class DecimalFloatAdapter extends jakarta.xml.bind.annotation.adapters.XmlAdapter<String,Float>

An adapter for converting between String and Float values during XML serialization and deserialization.

This implementation ensures that float values are serialized as integers if they have no digits after the decimal point. For example:

  • A float value of 5.0 will be serialized as "5".
  • A float value of 5.5 will remain serialized as "5.5".
  • Constructor Details

    • DecimalFloatAdapter

      public DecimalFloatAdapter()
  • Method Details

    • unmarshal

      public Float unmarshal(String v) throws Exception
      Converts a String value from the XML into a Float object.
      Specified by:
      unmarshal in class jakarta.xml.bind.annotation.adapters.XmlAdapter<String,Float>
      Parameters:
      v - The string value to be converted.
      Returns:
      The parsed Float value.
      Throws:
      Exception - If the string cannot be parsed as a float.
    • marshal

      public String marshal(Float v) throws Exception

      Converts a Float value into a String for XML serialization.

      If the float value is null, this method returns null. If the float value has no digits after the decimal point, it is serialized as an integer string. Otherwise, it is serialized as a standard float string.

      Specified by:
      marshal in class jakarta.xml.bind.annotation.adapters.XmlAdapter<String,Float>
      Parameters:
      v - The float value to be converted.
      Returns:
      The string representation of the float value.
      Throws:
      Exception - If an error occurs during conversion.