Class TomlBindOptions
Options are immutable, and hold what they learn about each Java type bound or written with them, so reusing one set of options for many bindings avoids examining the same classes again.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow the name of a field or record component is turned into a TOML key. -
Method Summary
Modifier and TypeMethodDescriptionstatic TomlBindOptionsdefaults()The default bind options: keys are the names of fields and record components, unchanged, a key with no field or component is an error, and no converters are registered.booleaninthashCode()booleanWhether a key with no field or record component is ignored.How names of fields and record components are turned into keys.toString()<T> TomlBindOptionswithConverter(Class<T> type, Function<Object, ? extends T> converter) Create a copy of these options that binds values to a type with a converter.<T> TomlBindOptionswithConverter(Class<T> type, Function<Object, ? extends T> read, Function<? super T, ?> write) Create a copy of these options that binds values to a type with a converter, and writes values of the type with another.withKeyNaming(TomlBindOptions.KeyNaming keyNaming) Create a copy of these options that turns names into keys with a different key naming.withUnknownKeysIgnored(boolean ignored) Create a copy of these options that ignores keys with no field or record component, or that reports them.
-
Method Details
-
defaults
The default bind options: keys are the names of fields and record components, unchanged, a key with no field or component is an error, and no converters are registered.- Returns:
- The default bind options.
-
withKeyNaming
Create a copy of these options that turns names into keys with a different key naming.- Parameters:
keyNaming- The key naming.- Returns:
- A new set of options with the given key naming.
-
withUnknownKeysIgnored
Create a copy of these options that ignores keys with no field or record component, or that reports them.By default, a key in a table that is bound to a record or class, and that names none of its fields or components, is an error, which catches a misspelled key in a document.
- Parameters:
ignored-trueto ignore keys with no field or record component,falseto report each as an error.- Returns:
- A new set of options.
-
withConverter
Create a copy of these options that binds values to a type with a converter.The converter is given the value from the document: a
String,Long,Double,Boolean,OffsetDateTime,LocalDateTime,LocalDate,LocalTime,TomlArrayorTomlTable. It must return a value of the type, notnull. If it throws aRuntimeException, the value is reported as aTomlBindErrorwith the exception's message.A converter is used for fields, components and elements declared with exactly this type, and takes the place of the binding TomlJ would use otherwise. A converter registered earlier for the same type is replaced, and values of the type cannot be written as TOML; see
withConverter(Class, Function, Function)to write them.TomlBindOptions options = TomlBindOptions.defaults().withConverter(Duration.class, value -> Duration.parse((String) value));- Type Parameters:
T- The type the converter produces.- Parameters:
type- The type the converter produces.converter- The converter.- Returns:
- A new set of options with the given converter.
-
withConverter
public <T> TomlBindOptions withConverter(Class<T> type, Function<Object, ? extends T> read, Function<? super T, ?> write) Create a copy of these options that binds values to a type with a converter, and writes values of the type with another.readbinds values as the converter given towithConverter(Class, Function)does.writeis given a value of the type, nevernull, when an object is written as TOML, and returns the TOML value to write for it: any valueMutableTomlTable.set(String, Object)accepts, such as aString, a number, aMap, aList, or aTomlValueto choose how it is written. If it throws aRuntimeExceptionor returnsnull, writing throwsIllegalArgumentException.When a document is updated from an object, a value in the document is left as it is if
readconverts it to a value equal to the one being written, sowritedoes not have to return the same text as the document holds.TomlBindOptions options = TomlBindOptions .defaults() .withConverter(Duration.class, value -> Duration.parse((String) value), Duration::toString);- Type Parameters:
T- The type the converters produce and write.- Parameters:
type- The type the converters produce and write.read- The converter from TOML values.write- The converter to TOML values.- Returns:
- A new set of options with the given converters.
-
keyNaming
How names of fields and record components are turned into keys.- Returns:
- The key naming.
-
ignoresUnknownKeys
public boolean ignoresUnknownKeys()Whether a key with no field or record component is ignored.- Returns:
trueif such keys are ignored.
-
equals
-
hashCode
public int hashCode() -
toString
-