diff --git a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/AliasAsMapKeyExample.java b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/AliasAsMapKeyExample.java index 104e651f3..61eecae4c 100644 --- a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/AliasAsMapKeyExample.java +++ b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/AliasAsMapKeyExample.java @@ -30,6 +30,10 @@ public final class AliasAsMapKeyExample { private final Map integers; + private final Map doubles; + + private final Map rawDoubles; + private final Map safelongs; private final Map datetimes; @@ -43,14 +47,18 @@ private AliasAsMapKeyExample( Map rids, Map bearertokens, Map integers, + Map doubles, + Map rawDoubles, Map safelongs, Map datetimes, Map uuids) { - validateFields(strings, rids, bearertokens, integers, safelongs, datetimes, uuids); + validateFields(strings, rids, bearertokens, integers, doubles, rawDoubles, safelongs, datetimes, uuids); this.strings = Collections.unmodifiableMap(strings); this.rids = Collections.unmodifiableMap(rids); this.bearertokens = Collections.unmodifiableMap(bearertokens); this.integers = Collections.unmodifiableMap(integers); + this.doubles = Collections.unmodifiableMap(doubles); + this.rawDoubles = Collections.unmodifiableMap(rawDoubles); this.safelongs = Collections.unmodifiableMap(safelongs); this.datetimes = Collections.unmodifiableMap(datetimes); this.uuids = Collections.unmodifiableMap(uuids); @@ -76,6 +84,16 @@ public Map getIntegers() { return this.integers; } + @JsonProperty("doubles") + public Map getDoubles() { + return this.doubles; + } + + @JsonProperty("rawDoubles") + public Map getRawDoubles() { + return this.rawDoubles; + } + @JsonProperty("safelongs") public Map getSafelongs() { return this.safelongs; @@ -106,6 +124,8 @@ private boolean equalTo(AliasAsMapKeyExample other) { && this.rids.equals(other.rids) && this.bearertokens.equals(other.bearertokens) && this.integers.equals(other.integers) + && this.doubles.equals(other.doubles) + && this.rawDoubles.equals(other.rawDoubles) && this.safelongs.equals(other.safelongs) && this.datetimes.equals(other.datetimes) && this.uuids.equals(other.uuids); @@ -120,6 +140,8 @@ public int hashCode() { hash = 31 * hash + this.rids.hashCode(); hash = 31 * hash + this.bearertokens.hashCode(); hash = 31 * hash + this.integers.hashCode(); + hash = 31 * hash + this.doubles.hashCode(); + hash = 31 * hash + this.rawDoubles.hashCode(); hash = 31 * hash + this.safelongs.hashCode(); hash = 31 * hash + this.datetimes.hashCode(); hash = 31 * hash + this.uuids.hashCode(); @@ -133,8 +155,8 @@ public int hashCode() { @DoNotLog public String toString() { return "AliasAsMapKeyExample{strings: " + strings + ", rids: " + rids + ", bearertokens: " + bearertokens - + ", integers: " + integers + ", safelongs: " + safelongs + ", datetimes: " + datetimes + ", uuids: " - + uuids + '}'; + + ", integers: " + integers + ", doubles: " + doubles + ", rawDoubles: " + rawDoubles + ", safelongs: " + + safelongs + ", datetimes: " + datetimes + ", uuids: " + uuids + '}'; } private static void validateFields( @@ -142,6 +164,8 @@ private static void validateFields( Map rids, Map bearertokens, Map integers, + Map doubles, + Map rawDoubles, Map safelongs, Map datetimes, Map uuids) { @@ -150,6 +174,8 @@ private static void validateFields( missingFields = addFieldIfMissing(missingFields, rids, "rids"); missingFields = addFieldIfMissing(missingFields, bearertokens, "bearertokens"); missingFields = addFieldIfMissing(missingFields, integers, "integers"); + missingFields = addFieldIfMissing(missingFields, doubles, "doubles"); + missingFields = addFieldIfMissing(missingFields, rawDoubles, "rawDoubles"); missingFields = addFieldIfMissing(missingFields, safelongs, "safelongs"); missingFields = addFieldIfMissing(missingFields, datetimes, "datetimes"); missingFields = addFieldIfMissing(missingFields, uuids, "uuids"); @@ -163,7 +189,7 @@ private static List addFieldIfMissing(List prev, Object fieldVal List missingFields = prev; if (fieldValue == null) { if (missingFields == null) { - missingFields = new ArrayList<>(7); + missingFields = new ArrayList<>(9); } missingFields.add(fieldName); } @@ -186,6 +212,10 @@ public static final class Builder { private Map integers = new LinkedHashMap<>(); + private Map doubles = new LinkedHashMap<>(); + + private Map rawDoubles = new LinkedHashMap<>(); + private Map safelongs = new LinkedHashMap<>(); private Map datetimes = new LinkedHashMap<>(); @@ -200,6 +230,8 @@ public Builder from(AliasAsMapKeyExample other) { rids(other.getRids()); bearertokens(other.getBearertokens()); integers(other.getIntegers()); + doubles(other.getDoubles()); + rawDoubles(other.getRawDoubles()); safelongs(other.getSafelongs()); datetimes(other.getDatetimes()); uuids(other.getUuids()); @@ -283,6 +315,44 @@ public Builder integers(IntegerAliasExample key, ManyFieldExample value) { return this; } + @JsonSetter(value = "doubles", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) + public Builder doubles(@Nonnull Map doubles) { + checkNotBuilt(); + this.doubles = new LinkedHashMap<>(Preconditions.checkNotNull(doubles, "doubles cannot be null")); + return this; + } + + public Builder putAllDoubles(@Nonnull Map doubles) { + checkNotBuilt(); + this.doubles.putAll(Preconditions.checkNotNull(doubles, "doubles cannot be null")); + return this; + } + + public Builder doubles(DoubleAliasExample key, ManyFieldExample value) { + checkNotBuilt(); + this.doubles.put(key, value); + return this; + } + + @JsonSetter(value = "rawDoubles", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) + public Builder rawDoubles(@Nonnull Map rawDoubles) { + checkNotBuilt(); + this.rawDoubles = new LinkedHashMap<>(Preconditions.checkNotNull(rawDoubles, "rawDoubles cannot be null")); + return this; + } + + public Builder putAllRawDoubles(@Nonnull Map rawDoubles) { + checkNotBuilt(); + this.rawDoubles.putAll(Preconditions.checkNotNull(rawDoubles, "rawDoubles cannot be null")); + return this; + } + + public Builder rawDoubles(double key, ManyFieldExample value) { + checkNotBuilt(); + this.rawDoubles.put(key, value); + return this; + } + @JsonSetter(value = "safelongs", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) public Builder safelongs(@Nonnull Map safelongs) { checkNotBuilt(); @@ -344,7 +414,8 @@ public Builder uuids(UuidAliasExample key, ManyFieldExample value) { public AliasAsMapKeyExample build() { checkNotBuilt(); this._buildInvoked = true; - return new AliasAsMapKeyExample(strings, rids, bearertokens, integers, safelongs, datetimes, uuids); + return new AliasAsMapKeyExample( + strings, rids, bearertokens, integers, doubles, rawDoubles, safelongs, datetimes, uuids); } private void checkNotBuilt() { diff --git a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/DoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/DoubleAliasExample.java index 481ec0f03..c44a5412a 100644 --- a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/DoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/DoubleAliasExample.java @@ -77,7 +77,16 @@ public static DoubleAliasExample of(String value) { case "-Infinity": return DoubleAliasExample.of(Double.NEGATIVE_INFINITY); default: - throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + try { + double doubleValue = Double.parseDouble(value); + if (Double.toString(doubleValue).equals(value)) { + return DoubleAliasExample.of(doubleValue); + } else { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } } } } diff --git a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/SafeDoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/SafeDoubleAliasExample.java index 084aa9986..f8e0859f1 100644 --- a/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/SafeDoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/allexamples/com/palantir/product/SafeDoubleAliasExample.java @@ -80,7 +80,16 @@ public static SafeDoubleAliasExample of(@Safe String value) { case "-Infinity": return SafeDoubleAliasExample.of(Double.NEGATIVE_INFINITY); default: - throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + try { + double doubleValue = Double.parseDouble(value); + if (Double.toString(doubleValue).equals(value)) { + return SafeDoubleAliasExample.of(doubleValue); + } else { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } } } } diff --git a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/AliasAsMapKeyExample.java b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/AliasAsMapKeyExample.java index bdc4985da..b1e68e47b 100644 --- a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/AliasAsMapKeyExample.java +++ b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/AliasAsMapKeyExample.java @@ -30,6 +30,10 @@ public final class AliasAsMapKeyExample { private final Map integers; + private final Map doubles; + + private final Map rawDoubles; + private final Map safelongs; private final Map datetimes; @@ -43,14 +47,18 @@ private AliasAsMapKeyExample( Map rids, Map bearertokens, Map integers, + Map doubles, + Map rawDoubles, Map safelongs, Map datetimes, Map uuids) { - validateFields(strings, rids, bearertokens, integers, safelongs, datetimes, uuids); + validateFields(strings, rids, bearertokens, integers, doubles, rawDoubles, safelongs, datetimes, uuids); this.strings = Collections.unmodifiableMap(strings); this.rids = Collections.unmodifiableMap(rids); this.bearertokens = Collections.unmodifiableMap(bearertokens); this.integers = Collections.unmodifiableMap(integers); + this.doubles = Collections.unmodifiableMap(doubles); + this.rawDoubles = Collections.unmodifiableMap(rawDoubles); this.safelongs = Collections.unmodifiableMap(safelongs); this.datetimes = Collections.unmodifiableMap(datetimes); this.uuids = Collections.unmodifiableMap(uuids); @@ -76,6 +84,16 @@ public Map getIntegers() { return this.integers; } + @JsonProperty("doubles") + public Map getDoubles() { + return this.doubles; + } + + @JsonProperty("rawDoubles") + public Map getRawDoubles() { + return this.rawDoubles; + } + @JsonProperty("safelongs") public Map getSafelongs() { return this.safelongs; @@ -106,6 +124,8 @@ private boolean equalTo(AliasAsMapKeyExample other) { && this.rids.equals(other.rids) && this.bearertokens.equals(other.bearertokens) && this.integers.equals(other.integers) + && this.doubles.equals(other.doubles) + && this.rawDoubles.equals(other.rawDoubles) && this.safelongs.equals(other.safelongs) && this.datetimes.equals(other.datetimes) && this.uuids.equals(other.uuids); @@ -120,6 +140,8 @@ public int hashCode() { hash = 31 * hash + this.rids.hashCode(); hash = 31 * hash + this.bearertokens.hashCode(); hash = 31 * hash + this.integers.hashCode(); + hash = 31 * hash + this.doubles.hashCode(); + hash = 31 * hash + this.rawDoubles.hashCode(); hash = 31 * hash + this.safelongs.hashCode(); hash = 31 * hash + this.datetimes.hashCode(); hash = 31 * hash + this.uuids.hashCode(); @@ -133,8 +155,8 @@ public int hashCode() { @DoNotLog public String toString() { return "AliasAsMapKeyExample{strings: " + strings + ", rids: " + rids + ", bearertokens: " + bearertokens - + ", integers: " + integers + ", safelongs: " + safelongs + ", datetimes: " + datetimes + ", uuids: " - + uuids + '}'; + + ", integers: " + integers + ", doubles: " + doubles + ", rawDoubles: " + rawDoubles + ", safelongs: " + + safelongs + ", datetimes: " + datetimes + ", uuids: " + uuids + '}'; } private static void validateFields( @@ -142,6 +164,8 @@ private static void validateFields( Map rids, Map bearertokens, Map integers, + Map doubles, + Map rawDoubles, Map safelongs, Map datetimes, Map uuids) { @@ -150,6 +174,8 @@ private static void validateFields( missingFields = addFieldIfMissing(missingFields, rids, "rids"); missingFields = addFieldIfMissing(missingFields, bearertokens, "bearertokens"); missingFields = addFieldIfMissing(missingFields, integers, "integers"); + missingFields = addFieldIfMissing(missingFields, doubles, "doubles"); + missingFields = addFieldIfMissing(missingFields, rawDoubles, "rawDoubles"); missingFields = addFieldIfMissing(missingFields, safelongs, "safelongs"); missingFields = addFieldIfMissing(missingFields, datetimes, "datetimes"); missingFields = addFieldIfMissing(missingFields, uuids, "uuids"); @@ -163,7 +189,7 @@ private static List addFieldIfMissing(List prev, Object fieldVal List missingFields = prev; if (fieldValue == null) { if (missingFields == null) { - missingFields = new ArrayList<>(7); + missingFields = new ArrayList<>(9); } missingFields.add(fieldName); } @@ -186,6 +212,10 @@ public static final class Builder { private Map integers = new LinkedHashMap<>(); + private Map doubles = new LinkedHashMap<>(); + + private Map rawDoubles = new LinkedHashMap<>(); + private Map safelongs = new LinkedHashMap<>(); private Map datetimes = new LinkedHashMap<>(); @@ -200,6 +230,8 @@ public Builder from(AliasAsMapKeyExample other) { rids(other.getRids()); bearertokens(other.getBearertokens()); integers(other.getIntegers()); + doubles(other.getDoubles()); + rawDoubles(other.getRawDoubles()); safelongs(other.getSafelongs()); datetimes(other.getDatetimes()); uuids(other.getUuids()); @@ -283,6 +315,44 @@ public Builder integers(IntegerAliasExample key, ManyFieldExample value) { return this; } + @JsonSetter(value = "doubles", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) + public Builder doubles(@Nonnull Map doubles) { + checkNotBuilt(); + this.doubles = new LinkedHashMap<>(Preconditions.checkNotNull(doubles, "doubles cannot be null")); + return this; + } + + public Builder putAllDoubles(@Nonnull Map doubles) { + checkNotBuilt(); + this.doubles.putAll(Preconditions.checkNotNull(doubles, "doubles cannot be null")); + return this; + } + + public Builder doubles(DoubleAliasExample key, ManyFieldExample value) { + checkNotBuilt(); + this.doubles.put(key, value); + return this; + } + + @JsonSetter(value = "rawDoubles", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) + public Builder rawDoubles(@Nonnull Map rawDoubles) { + checkNotBuilt(); + this.rawDoubles = new LinkedHashMap<>(Preconditions.checkNotNull(rawDoubles, "rawDoubles cannot be null")); + return this; + } + + public Builder putAllRawDoubles(@Nonnull Map rawDoubles) { + checkNotBuilt(); + this.rawDoubles.putAll(Preconditions.checkNotNull(rawDoubles, "rawDoubles cannot be null")); + return this; + } + + public Builder rawDoubles(double key, ManyFieldExample value) { + checkNotBuilt(); + this.rawDoubles.put(key, value); + return this; + } + @JsonSetter(value = "safelongs", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL) public Builder safelongs(@Nonnull Map safelongs) { checkNotBuilt(); @@ -344,7 +414,8 @@ public Builder uuids(UuidAliasExample key, ManyFieldExample value) { public AliasAsMapKeyExample build() { checkNotBuilt(); this._buildInvoked = true; - return new AliasAsMapKeyExample(strings, rids, bearertokens, integers, safelongs, datetimes, uuids); + return new AliasAsMapKeyExample( + strings, rids, bearertokens, integers, doubles, rawDoubles, safelongs, datetimes, uuids); } private void checkNotBuilt() { diff --git a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/DoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/DoubleAliasExample.java index b8ccdf765..d196c54e8 100644 --- a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/DoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/DoubleAliasExample.java @@ -77,7 +77,16 @@ public static DoubleAliasExample of(String value) { case "-Infinity": return DoubleAliasExample.of(Double.NEGATIVE_INFINITY); default: - throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + try { + double doubleValue = Double.parseDouble(value); + if (Double.toString(doubleValue).equals(value)) { + return DoubleAliasExample.of(doubleValue); + } else { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } } } } diff --git a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/SafeDoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/SafeDoubleAliasExample.java index 9419aaa93..ae8a6228e 100644 --- a/conjure-java-core/src/integrationInput/java/template/com/palantir/product/SafeDoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/template/com/palantir/product/SafeDoubleAliasExample.java @@ -80,7 +80,16 @@ public static SafeDoubleAliasExample of(@Safe String value) { case "-Infinity": return SafeDoubleAliasExample.of(Double.NEGATIVE_INFINITY); default: - throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + try { + double doubleValue = Double.parseDouble(value); + if (Double.toString(doubleValue).equals(value)) { + return SafeDoubleAliasExample.of(doubleValue); + } else { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } } } } diff --git a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/AliasedDouble.java b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/AliasedDouble.java index eccc78296..f74927314 100644 --- a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/AliasedDouble.java +++ b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/AliasedDouble.java @@ -77,7 +77,16 @@ public static AliasedDouble of(String value) { case "-Infinity": return AliasedDouble.of(Double.NEGATIVE_INFINITY); default: - throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + try { + double doubleValue = Double.parseDouble(value); + if (Double.toString(doubleValue).equals(value)) { + return AliasedDouble.of(doubleValue); + } else { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Cannot deserialize string into double: " + value); + } } } } diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java index 6870b1acc..f0274f407 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java @@ -208,9 +208,20 @@ public static JavaFile generateAliasType( .unindent() .add("default:\n") .indent() + .beginControlFlow("try") + .addStatement("double doubleValue = $T.parseDouble(value)", Double.class) + .beginControlFlow("if ($T.toString(doubleValue).equals(value))", Double.class) + .addStatement("return $T.of(doubleValue)", thisClass) + .nextControlFlow("else") .addStatement( "throw new $T(\"Cannot deserialize string into double: \" + value)", IllegalArgumentException.class) + .endControlFlow() + .nextControlFlow("catch ($T e)", NumberFormatException.class) + .addStatement( + "throw new $T(\"Cannot deserialize string into double: \" + value)", + IllegalArgumentException.class) + .endControlFlow() .unindent() .endControlFlow() .build(); diff --git a/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java b/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java index b63b0da8b..d628ad2fb 100644 --- a/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java +++ b/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import allexamples.com.palantir.product.AliasAsMapKeyExample; import allexamples.com.palantir.product.BinaryAliasExample; import allexamples.com.palantir.product.BinaryExample; import allexamples.com.palantir.product.DateTimeExample; @@ -31,6 +32,7 @@ import allexamples.com.palantir.product.IntegerAliasExample; import allexamples.com.palantir.product.ListAlias; import allexamples.com.palantir.product.ListExample; +import allexamples.com.palantir.product.ManyFieldExample; import allexamples.com.palantir.product.MapAliasExample; import allexamples.com.palantir.product.MapExample; import allexamples.com.palantir.product.OptionalAlias; @@ -85,6 +87,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; @Execution(ExecutionMode.CONCURRENT) public final class WireFormatTests { @@ -534,12 +538,56 @@ public void double_alias_should_serialize_with_decimal_point() throws Exception assertThat(mapper.writeValueAsString(DoubleAliasExample.of(100L))).isEqualTo("100.0"); } + @Test + public void double_alias_should_serialize_with_e() throws Exception { + assertThat(mapper.writeValueAsString(DoubleAliasExample.of(100e20))).isEqualTo("1.0E22"); + } + @Test public void double_alias_should_deserialize_without_decimal_point() throws Exception { // frontends can send numbers like this! assertThat(mapper.readValue("100", DoubleAliasExample.class)).isEqualTo(DoubleAliasExample.of(100L)); } + @ParameterizedTest + @ValueSource(doubles = {1, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, -0.0, 1e20}) + public void double_alias_map_key_should_serialize_as_string(Double doubleKey) throws Exception { + ManyFieldExample value = ManyFieldExample.builder() + .integer(1) + .doubleValue(doubleKey) + .string("hello") + .alias(StringAliasExample.of("hello")) + .build(); + + String doubleValue = Set.of(Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY) + .contains(doubleKey) + ? "\"" + doubleKey + "\"" + : doubleKey.toString(); + + String expectedPretty = String.format( + """ + { + "strings":{}, + "rids":{}, + "bearertokens":{}, + "integers":{}, + "doubles":{"%s": {"string":"hello","integer":1,"doubleValue":%s,"items":[],"set":[],"map":{},"alias":"hello"}}, + "rawDoubles":{"%s": {"string":"hello","integer":1,"doubleValue":%s,"items":[],"set":[],"map":{},"alias":"hello"}}, + "safelongs":{}, + "datetimes":{}, + "uuids":{} + } + """, + doubleKey, doubleValue, doubleKey, doubleValue); + String expected = expectedPretty.strip().replaceAll("\n", "").replaceAll(" ", ""); + AliasAsMapKeyExample example = AliasAsMapKeyExample.builder() + .doubles(ImmutableMap.of(DoubleAliasExample.of(doubleKey), value)) + .rawDoubles(doubleKey, value) + .build(); + assertThat(mapper.writeValueAsString(example)).isEqualTo(expected); + assertThat(mapper.readValue(expected, AliasAsMapKeyExample.class)).isEqualTo(example); + } + @Test public void testUuidType_roundTrip() throws Exception { String serialized = "{\"uuid\":\"0db30881-8f3e-46f4-a8bb-df5883bf7eb8\"}"; diff --git a/conjure-java-core/src/test/resources/example-types.yml b/conjure-java-core/src/test/resources/example-types.yml index 4af183f6f..4e0e6290a 100644 --- a/conjure-java-core/src/test/resources/example-types.yml +++ b/conjure-java-core/src/test/resources/example-types.yml @@ -261,7 +261,8 @@ types: rids: map bearertokens: map integers: map - # doubles: map # typescript freaks out with the 'NaN' + doubles: map # typescript freaks out with the 'NaN' + rawDoubles: map safelongs: map datetimes: map uuids: map