diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/BearerTokenAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/BearerTokenAliasExample.java index f0a7bd905..1ea432710 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/BearerTokenAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/BearerTokenAliasExample.java @@ -37,6 +37,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static BearerTokenAliasExample valueOf(String value) { return new BearerTokenAliasExample(BearerToken.valueOf(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/BooleanAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/BooleanAliasExample.java index c45d67d8f..8636b06b9 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/BooleanAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/BooleanAliasExample.java @@ -34,6 +34,7 @@ public int hashCode() { return Boolean.hashCode(value); } + @JsonCreator public static BooleanAliasExample valueOf(String value) { return new BooleanAliasExample(Boolean.parseBoolean(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/DateTimeAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/DateTimeAliasExample.java index 712b810ad..c2294383b 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/DateTimeAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/DateTimeAliasExample.java @@ -37,6 +37,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static DateTimeAliasExample valueOf(String value) { return new DateTimeAliasExample(ZonedDateTime.parse(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java index 5da0b726d..98d38372f 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java @@ -34,6 +34,7 @@ public int hashCode() { return Double.hashCode(value); } + @JsonCreator public static DoubleAliasExample valueOf(String value) { return new DoubleAliasExample(Double.parseDouble(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/IntegerAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/IntegerAliasExample.java index 6849caebe..a2e547df3 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/IntegerAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/IntegerAliasExample.java @@ -34,6 +34,7 @@ public int hashCode() { return Integer.hashCode(value); } + @JsonCreator public static IntegerAliasExample valueOf(String value) { return new IntegerAliasExample(Integer.parseInt(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/RidAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/RidAliasExample.java index f4048d64a..51bdefbae 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/RidAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/RidAliasExample.java @@ -37,6 +37,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static RidAliasExample valueOf(String value) { return new RidAliasExample(ResourceIdentifier.valueOf(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongAliasExample.java index e885d8235..643842a15 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeLongAliasExample.java @@ -37,6 +37,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static SafeLongAliasExample valueOf(String value) { return new SafeLongAliasExample(SafeLong.valueOf(value)); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/StringAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/StringAliasExample.java index 66b58b8fa..c357565c2 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/StringAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/StringAliasExample.java @@ -36,6 +36,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static StringAliasExample valueOf(String value) { return new StringAliasExample(value); } diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/UuidAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/UuidAliasExample.java index d8f0a8e6f..470dbb65a 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/UuidAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/UuidAliasExample.java @@ -37,6 +37,7 @@ public int hashCode() { return value.hashCode(); } + @JsonCreator public static UuidAliasExample valueOf(String value) { return new UuidAliasExample(UUID.fromString(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 bfec87687..1371e37d6 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 @@ -82,6 +82,7 @@ public static JavaFile generateAliasType( if (maybeValueOfFactoryMethod.isPresent()) { spec.addMethod(MethodSpec.methodBuilder("valueOf") .addModifiers(Modifier.PUBLIC, Modifier.STATIC) + .addAnnotation(JsonCreator.class) .addParameter(String.class, "value") .returns(thisClass) .addCode(maybeValueOfFactoryMethod.get()) 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 8c65b9fbd..43d3ef617 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 @@ -161,6 +161,12 @@ public void testAliasTypesEqualWhenInnerTypeEqual() throws Exception { assertThat(BinaryAliasExample.of(byteBuffer)).isEqualTo(BinaryAliasExample.of(byteBuffer)); } + @Test + public void testPrimitiveAliasTypesCanBeDeserializedFromString() throws Exception { + assertThat(mapper.readValue("\"123\"", IntegerAliasExample.class)).isEqualTo(IntegerAliasExample.of(123)); + assertThat(mapper.readValue("\"123.0\"", DoubleAliasExample.class)).isEqualTo(DoubleAliasExample.of(123.0)); + } + @Test public void testAliasTypesHashCodeEqualWhenInnerTypeEqual() throws Exception { assertThat(StringAliasExample.of("a").hashCode()).isEqualTo(StringAliasExample.of("a").hashCode()); diff --git a/versions.props b/versions.props index ad6b8bc52..96ed890f6 100644 --- a/versions.props +++ b/versions.props @@ -1,5 +1,4 @@ -com.fasterxml.jackson.*:jackson-* = 2.7.4 -com.fasterxml.jackson.datatype:jackson-datatype-jdk7 = 2.6.7 +com.fasterxml.jackson.*:jackson-* = 2.9.6 com.google.code.findbugs:jsr305 = 3.0.2 com.google.errorprone:error_prone_annotations = 2.3.1 com.google.googlejavaformat:google-java-format = 1.5