Skip to content

Commit

Permalink
[1.2.0-SNAPSHOT]
Browse files Browse the repository at this point in the history
GsonConfiguration#forceResolverStrict and GsonConfiguration#forceIsoChronology properties support and tests added
  • Loading branch information
GoodforGod committed Jan 18, 2022
1 parent e1363ea commit 207e44b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ private static GsonConfiguration ofProperties(GsonConfiguration configuration, P
final String formatMonthDay = properties.getProperty(GsonProperties.FORMAT_MONTH_DAY);
final String formatDate = properties.getProperty(GsonProperties.FORMAT_DATE);

final String forceIsoChronologyProp = properties.getProperty(GsonProperties.FORCE_ISO_CHRONOLOGY);
final String forceResolverStrictProp = properties.getProperty(GsonProperties.FORCE_RESOLVER_STRICT);

final String fieldNamingPolicy = properties.getProperty(GsonProperties.POLICY_FIELD_NAMING);
final String longSerializationPolicy = properties.getProperty(GsonProperties.POLICY_LONG_SERIALIZATION);

Expand Down Expand Up @@ -188,6 +191,11 @@ private static GsonConfiguration ofProperties(GsonConfiguration configuration, P
if (formatDate != null)
configuration.setDateFormat(formatDate);

if (forceIsoChronologyProp != null)
configuration.setForceIsoChronology(Boolean.parseBoolean(forceIsoChronologyProp));
if (forceResolverStrictProp != null)
configuration.setForceResolverStrict(Boolean.parseBoolean(forceResolverStrictProp));

if (fieldNamingPolicy != null)
configuration.setFieldNamingPolicy(FieldNamingPolicy.valueOf(fieldNamingPolicy));
if (longSerializationPolicy != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ private GsonProperties() {}
public static final String FORMAT_MONTH_DAY = PREFIX + "format.monthDay";
public static final String FORMAT_DATE = PREFIX + "format.date";

public static final String FORCE_ISO_CHRONOLOGY = PREFIX + "forceIsoChronology";
public static final String FORCE_RESOLVER_STRICT = PREFIX + "forceResolverStrict";

public static final String LENIENT = PREFIX + "lenient";
public static final String SERIALIZE_NULLS = PREFIX + "serializeNulls";
public static final String PRETTY_PRINTING = PREFIX + "prettyPrinting";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ void configurationPropertiesApplied() throws Exception {
assertNotNull(configuration.getOffsetTimeFormat());
assertNotNull(configuration.getOffsetDateTimeFormat());

assertTrue(configuration.isForceIsoChronology());
assertTrue(configuration.isForceResolverStrict());

assertTrue(configuration.isLenient());
assertTrue(configuration.isComplexMapKeySerialization());
assertTrue(configuration.isPrettyPrinting());
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/gson.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ gson.format.yearMonth=uuuu-MM
gson.format.monthDay=MM-dd
gson.format.date=uuuu-MM-dd'T'HH:mm:ss.SSSXXX

gson.forceIsoChronology=true
gson.forceResolverStrict=true

gson.lenient=true
gson.serializeNulls=true
gson.prettyPrinting=true
Expand Down

0 comments on commit 207e44b

Please sign in to comment.