From e3cf82cf5943902fb145d52c4db55c2f394ea7f1 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Thu, 3 Aug 2023 21:56:31 +0900 Subject: [PATCH 1/7] Add new JsonTypeInfo.Id.SIMPLE_NAME --- .../jackson/annotation/JsonTypeInfo.java | 17 +++++++++++++++++ .../jackson/annotation/JsonTypeInfoTest.java | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index e16c7414..e64a83f1 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -119,6 +119,23 @@ public enum Id { */ NAME("@type"), + /** + * Means that the simple name of the Java class, as returned by {@link Class#getSimpleName()}, + * is used as the type identifier. + *
+ * For instance: + * + * NOTE: This approach reduces verbosity but expects the simple names to be unique + * to avoid conflicts. If multiple classes have the same simple name, the first one declared + * will be used. Use this approach with careful consideration of your type hierarchy. + * + * @since 2.16 + */ + SIMPLE_NAME("@simpl"), + /** * Means that no serialized typing-property is used. Types are deduced based * on the fields available. Deduction is limited to the names of fields diff --git a/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java b/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java index 82b76ccc..52e67848 100644 --- a/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java +++ b/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java @@ -61,6 +61,8 @@ public void testMutators() throws Exception assertSame(v, v.withIdType(JsonTypeInfo.Id.CLASS)); JsonTypeInfo.Value v2 = v.withIdType(JsonTypeInfo.Id.MINIMAL_CLASS); assertEquals(JsonTypeInfo.Id.MINIMAL_CLASS, v2.getIdType()); + JsonTypeInfo.Value v3 = v.withIdType(JsonTypeInfo.Id.SIMPLE_NAME); + assertEquals(JsonTypeInfo.Id.SIMPLE_NAME, v3.getIdType()); assertEquals(JsonTypeInfo.As.PROPERTY, v.getInclusionType()); assertSame(v, v.withInclusionType(JsonTypeInfo.As.PROPERTY)); From 82ff453c244f26d0c6a4b5c523c21fa39a81cbb4 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Thu, 3 Aug 2023 22:00:22 +0900 Subject: [PATCH 2/7] Update JsonTypeInfo.java --- .../com/fasterxml/jackson/annotation/JsonTypeInfo.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index e64a83f1..e4b056b3 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -120,17 +120,17 @@ public enum Id { NAME("@type"), /** - * Means that the simple name of the Java class, as returned by {@link Class#getSimpleName()}, + * Means that the simple name of the Java class, equivalent to the value returned by {@link Class#getSimpleName()}, * is used as the type identifier. *
* For instance: * - * NOTE: This approach reduces verbosity but expects the simple names to be unique - * to avoid conflicts. If multiple classes have the same simple name, the first one declared - * will be used. Use this approach with careful consideration of your type hierarchy. + * Note: This approach reduces verbosity but requires the simple names to be unique + * to avoid conflicts. If multiple classes share the same simple name, the first one declared + * will be used. This approach should be used with careful consideration of your type hierarchy. * * @since 2.16 */ From e28e6ed928635b91c400a6930a99ab27dba7db56 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Thu, 3 Aug 2023 22:01:08 +0900 Subject: [PATCH 3/7] Update JsonTypeInfo.java --- .../java/com/fasterxml/jackson/annotation/JsonTypeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index e4b056b3..195cd2ca 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -129,7 +129,7 @@ public enum Id { *
  • For an inner class "com.example.MyClass$Inner", only "Inner" is used.
  • * * Note: This approach reduces verbosity but requires the simple names to be unique - * to avoid conflicts. If multiple classes share the same simple name, the first one declared + * to avoid conflicts. If multiple classes share the same simple name, the first one declared * will be used. This approach should be used with careful consideration of your type hierarchy. * * @since 2.16 From ccc108b42a5629ac2673fee02f372fc8b768d39f Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Thu, 3 Aug 2023 23:21:10 +0900 Subject: [PATCH 4/7] Make dedup rule "last one wins" --- .../java/com/fasterxml/jackson/annotation/JsonTypeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index 195cd2ca..f57a0539 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -129,7 +129,7 @@ public enum Id { *
  • For an inner class "com.example.MyClass$Inner", only "Inner" is used.
  • * * Note: This approach reduces verbosity but requires the simple names to be unique - * to avoid conflicts. If multiple classes share the same simple name, the first one declared + * to avoid conflicts. If multiple classes share the same simple name, the last declared one * will be used. This approach should be used with careful consideration of your type hierarchy. * * @since 2.16 From e5e16536a6e134d645fb688c60141f5b3830435b Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Fri, 4 Aug 2023 07:09:23 +0900 Subject: [PATCH 5/7] Fix typo --- .../java/com/fasterxml/jackson/annotation/JsonTypeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index f57a0539..f43b2c76 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -134,7 +134,7 @@ public enum Id { * * @since 2.16 */ - SIMPLE_NAME("@simpl"), + SIMPLE_NAME("@simple"), /** * Means that no serialized typing-property is used. Types are deduced based From 908cbe414f27f04c9df3fa0c3880491004fe2f82 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Fri, 4 Aug 2023 07:11:02 +0900 Subject: [PATCH 6/7] Update JsonTypeInfo.java --- .../java/com/fasterxml/jackson/annotation/JsonTypeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index f43b2c76..c3bf2ec4 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -121,7 +121,7 @@ public enum Id { /** * Means that the simple name of the Java class, equivalent to the value returned by {@link Class#getSimpleName()}, - * is used as the type identifier. + * is used as the default type identifier, unless explicit name is specified by annotation {@link JsonTypeName}. *
    * For instance: *
      From 1ece541422ef22a98c626757724bac4f51c20f59 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Fri, 4 Aug 2023 13:06:05 +0900 Subject: [PATCH 7/7] Change default prop --- .../java/com/fasterxml/jackson/annotation/JsonTypeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index c3bf2ec4..47de0633 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -134,7 +134,7 @@ public enum Id { * * @since 2.16 */ - SIMPLE_NAME("@simple"), + SIMPLE_NAME("@type"), /** * Means that no serialized typing-property is used. Types are deduced based