Interface ToStringProvider<C>

All Superinterfaces:
Comparable<ToStringProvider<?>>
All Known Implementing Classes:
AbstractToString, BooleanToString, DoubleToString, EnumToString, FloatToString, IntegerToString, LongToString, NumberToString, StringToString

public interface ToStringProvider<C> extends Comparable<ToStringProvider<?>>
SPI to serialize and deserialize to and from String, without resorting to serialization.

E.g. a MathContext can be serialized, but can also be written to String and parsed by very naturally.

This can only be used if the type is known beforehand.

  • Method Summary

    Modifier and Type
    Method
    Description
    default int
     
    fromString(Class<?> type, @Nullable String value)
    Given a desired type, and a string value, convert it to the supported type.
    toString(@Nullable Object value)
    For given value, check if the type is supported, and then convert it to a String.
    int
     
  • Method Details

    • weight

      int weight()
    • toString

      Optional<String> toString(@Nullable Object value)
      For given value, check if the type is supported, and then convert it to a String.
    • fromString

      Optional<C> fromString(Class<?> type, @Nullable String value)
      Given a desired type, and a string value, convert it to the supported type. Normally, the given type must be some superclass of C, but it also might be a primitive type.
    • compareTo

      default int compareTo(ToStringProvider other)
      Specified by:
      compareTo in interface Comparable<C>