Package io.goodforgod.gson.configuration
Class GsonConfiguration
java.lang.Object
io.goodforgod.gson.configuration.GsonConfiguration
- Since:
- 25.04.2021
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.gson.GsonBuilderbuilder()com.google.gson.FieldNamingPolicycom.google.gson.LongSerializationPolicybooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanstatic GsonConfigurationofProperties(Properties properties) setComplexMapKeySerialization(boolean complexMapKeySerialization) Enabling this feature will only change the serialized form if the map key is a complex type (i.e.setDateFormat(String dateFormat) setEscapeHtmlChars(boolean escapeHtmlChars) Use this option to configure Gson to pass-through HTML characters as is.setExcludeFieldsWithModifiers(GsonConfiguration.FieldModifiers... excludeFieldsWithModifiers) Configures Gson to excludes all class fields that have the specified modifiers.setExcludeFieldsWithModifiers(Set<GsonConfiguration.FieldModifiers> excludeFieldsWithModifiers) Configures Gson to excludes all class fields that have the specified modifiers.setExcludeFieldsWithoutExposeAnnotation(boolean excludeFieldsWithoutExposeAnnotation) Configures Gson to exclude all fields from consideration for serialization or deserialization that do not have theExposeannotation.setFieldNamingPolicy(com.google.gson.FieldNamingPolicy fieldNamingPolicy) Configures Gson to apply a specific naming policy to an object's field during serialization and deserialization.setForceIsoChronology(boolean forceIsoChronology) ForcesIsoChronology.INSTANCEfor all formatters setterssetForceResolverStrict(boolean forceResolverStrict) ForcesResolverStyle.STRICTfor all formatters setterssetGenerateNonExecutableJson(boolean generateNonExecutableJson) Makes the output JSON non-executable in Javascript by prefixing the generated JSON with some special text.setInstantFormat(String instantPattern) setInstantFormat(DateTimeFormatter instantFormat) setLenient(boolean lenient) This option makes the parser liberal in what it accepts.setLocalDateFormat(String localDatePattern) setLocalDateFormat(DateTimeFormatter localDateFormat) setLocalDateTimeFormat(String localDateTimePattern) setLocalDateTimeFormat(DateTimeFormatter localDateTimeFormat) setLocalTimeFormat(String localTimePattern) setLocalTimeFormat(DateTimeFormatter localTimeFormat) setLongSerializationPolicy(com.google.gson.LongSerializationPolicy longSerializationPolicy) Configures Gson to apply a specific serialization policy forLongandlongobjects.setMonthDayFormat(String monthDayPattern) setMonthDayFormat(DateTimeFormatter monthDayFormat) setOffsetDateTimeFormat(String offsetDateTimePattern) setOffsetDateTimeFormat(DateTimeFormatter offsetDateTimeFormat) setOffsetTimeFormat(String offsetTimePattern) setOffsetTimeFormat(DateTimeFormatter offsetTimeFormat) setPrettyPrinting(boolean prettyPrinting) Configures Gson to output Json that fits in a page for pretty printing.setSerializeNulls(boolean serializeNulls) Configure Gson to serialize null fields.setSerializeSpecialFloatingPointValues(boolean serializeSpecialFloatingPointValues) This method provides a way to not throw exception when you have special floating values likeFloat.NaN,Float.POSITIVE_INFINITY,Float.NEGATIVE_INFINITY, or a double valueDouble.NaN,Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY.setYearFormat(String yearPattern) setYearFormat(DateTimeFormatter yearFormat) setYearMonthFormat(String yearMonthPattern) setYearMonthFormat(DateTimeFormatter yearMonthFormat) setZonedDateTimeFormat(String zonedDateTimePattern) setZonedDateTimeFormat(DateTimeFormatter zonedDateTimeFormat)
-
Constructor Details
-
GsonConfiguration
public GsonConfiguration()
-
-
Method Details
-
ofProperties
-
builder
public com.google.gson.GsonBuilder builder() -
getDateFormat
-
setDateFormat
-
isForceResolverStrict
public boolean isForceResolverStrict() -
setForceResolverStrict
ForcesResolverStyle.STRICTfor all formatters setters -
isForceIsoChronology
public boolean isForceIsoChronology() -
setForceIsoChronology
ForcesIsoChronology.INSTANCEfor all formatters setters -
getFieldNamingPolicy
public com.google.gson.FieldNamingPolicy getFieldNamingPolicy() -
setFieldNamingPolicy
Configures Gson to apply a specific naming policy to an object's field during serialization and deserialization.- Parameters:
fieldNamingPolicy- to set- Returns:
- self
-
getLongSerializationPolicy
public com.google.gson.LongSerializationPolicy getLongSerializationPolicy() -
setLongSerializationPolicy
public GsonConfiguration setLongSerializationPolicy(com.google.gson.LongSerializationPolicy longSerializationPolicy) Configures Gson to apply a specific serialization policy forLongandlongobjects.- Parameters:
longSerializationPolicy- policy to set- Returns:
- self
-
isSerializeNulls
public boolean isSerializeNulls() -
setSerializeNulls
Configure Gson to serialize null fields. By default, Gson omits all fields that are null during serialization.- Parameters:
serializeNulls- true if serialize- Returns:
- self
-
isComplexMapKeySerialization
public boolean isComplexMapKeySerialization() -
setComplexMapKeySerialization
Enabling this feature will only change the serialized form if the map key is a complex type (i.e. non-primitive) in its serialized JSON form.- Parameters:
complexMapKeySerialization- to set- Returns:
- self
-
isGenerateNonExecutableJson
public boolean isGenerateNonExecutableJson() -
setGenerateNonExecutableJson
Makes the output JSON non-executable in Javascript by prefixing the generated JSON with some special text.- Parameters:
generateNonExecutableJson- to set- Returns:
- self
-
isEscapeHtmlChars
public boolean isEscapeHtmlChars() -
setEscapeHtmlChars
Use this option to configure Gson to pass-through HTML characters as is.- Parameters:
escapeHtmlChars- to set- Returns:
- self
-
isPrettyPrinting
public boolean isPrettyPrinting() -
setPrettyPrinting
Configures Gson to output Json that fits in a page for pretty printing.- Parameters:
prettyPrinting- to set- Returns:
- self
-
isLenient
public boolean isLenient() -
setLenient
This option makes the parser liberal in what it accepts.- Parameters:
lenient- to set- Returns:
- self
-
isSerializeSpecialFloatingPointValues
public boolean isSerializeSpecialFloatingPointValues() -
setSerializeSpecialFloatingPointValues
public GsonConfiguration setSerializeSpecialFloatingPointValues(boolean serializeSpecialFloatingPointValues) This method provides a way to not throw exception when you have special floating values likeFloat.NaN,Float.POSITIVE_INFINITY,Float.NEGATIVE_INFINITY, or a double valueDouble.NaN,Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY.- Parameters:
serializeSpecialFloatingPointValues- to set- Returns:
- self
-
isExcludeFieldsWithoutExposeAnnotation
public boolean isExcludeFieldsWithoutExposeAnnotation() -
setExcludeFieldsWithoutExposeAnnotation
public GsonConfiguration setExcludeFieldsWithoutExposeAnnotation(boolean excludeFieldsWithoutExposeAnnotation) Configures Gson to exclude all fields from consideration for serialization or deserialization that do not have theExposeannotation.- Parameters:
excludeFieldsWithoutExposeAnnotation- set true to exclude- Returns:
- self
- See Also:
-
GsonBuilder.excludeFieldsWithoutExposeAnnotation()
-
getExcludeFieldsWithModifiers
-
setExcludeFieldsWithModifiers
public GsonConfiguration setExcludeFieldsWithModifiers(Set<GsonConfiguration.FieldModifiers> excludeFieldsWithModifiers) Configures Gson to excludes all class fields that have the specified modifiers. By default, Gson will exclude all fields marked transient or static. This method will override that behavior.- Parameters:
excludeFieldsWithModifiers- fields modifiers to exclude- Returns:
- self
- See Also:
-
GsonBuilder.excludeFieldsWithModifiers(int...)
-
setExcludeFieldsWithModifiers
public GsonConfiguration setExcludeFieldsWithModifiers(GsonConfiguration.FieldModifiers... excludeFieldsWithModifiers) Configures Gson to excludes all class fields that have the specified modifiers. By default, Gson will exclude all fields marked transient or static. This method will override that behavior.- Parameters:
excludeFieldsWithModifiers- fields modifiers to exclude- Returns:
- self
- See Also:
-
GsonBuilder.excludeFieldsWithModifiers(int...)
-
getInstantFormat
-
setInstantFormat
-
setInstantFormat
-
getLocalDateFormat
-
setLocalDateFormat
-
setLocalDateFormat
-
getLocalTimeFormat
-
setLocalTimeFormat
-
setLocalTimeFormat
-
getLocalDateTimeFormat
-
setLocalDateTimeFormat
-
setLocalDateTimeFormat
-
getOffsetTimeFormat
-
setOffsetTimeFormat
-
setOffsetTimeFormat
-
getOffsetDateTimeFormat
-
setOffsetDateTimeFormat
-
setOffsetDateTimeFormat
-
getZonedDateTimeFormat
-
setZonedDateTimeFormat
-
setZonedDateTimeFormat
-
getYearFormat
-
setYearFormat
-
setYearFormat
-
getYearMonthFormat
-
setYearMonthFormat
-
setYearMonthFormat
-
getMonthDayFormat
-
setMonthDayFormat
-
setMonthDayFormat
-