Skip to content

Commit abadc05

Browse files
authored
Fix #3742: from schemaType for LongSerializer (and ShortSerializer) (#3743)
1 parent ae3ca88 commit abadc05

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project: jackson-databind
2727
#3708: Seems like `java.nio.file.Path` is safe for Android API level 26
2828
(contributed by @pjfanning)
2929
#3736: Try to avoid auto-detecting Fields for Record types
30+
#3742: schemaType of `LongSerializer` is wrong
31+
(reported by @luozhenyu)
3032

3133
2.14.2 (not yet released)
3234

src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static class ShortSerializer extends Base<Object> {
121121
final static ShortSerializer instance = new ShortSerializer();
122122

123123
public ShortSerializer() {
124-
super(Short.class, JsonParser.NumberType.INT, "number");
124+
super(Short.class, JsonParser.NumberType.INT, "integer");
125125
}
126126

127127
@Override
@@ -186,7 +186,7 @@ public void serialize(Object value, JsonGenerator gen,
186186
@JacksonStdImpl
187187
public static class LongSerializer extends Base<Object> {
188188
public LongSerializer(Class<?> cls) {
189-
super(cls, JsonParser.NumberType.LONG, "number");
189+
super(cls, JsonParser.NumberType.LONG, "integer");
190190
}
191191

192192
@Override

src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static class SimpleBean
3434
private Collection<Float> property4;
3535
@JsonProperty(required=true)
3636
private String property5;
37-
37+
3838
public int getProperty1()
3939
{
4040
return property1;
@@ -80,10 +80,13 @@ public String getProperty5()
8080
return property5;
8181
}
8282

83-
public void setProperty5(String property5)
84-
{
83+
public void setProperty5(String property5) {
8584
this.property5 = property5;
8685
}
86+
87+
public long getProperty6() {
88+
return 0L;
89+
}
8790
}
8891

8992
public class TrivialBean {
@@ -119,7 +122,7 @@ static class Numbers {
119122
/**********************************************************
120123
*/
121124

122-
private final ObjectMapper MAPPER = new ObjectMapper();
125+
private final ObjectMapper MAPPER = newJsonMapper();
123126

124127
/**
125128
* tests generating json-schema stuff.
@@ -162,6 +165,16 @@ public void testOldSchemaGeneration() throws Exception
162165
assertEquals("array", property4Schema.get("type").asText());
163166
assertEquals(false, property4Schema.path("required").booleanValue());
164167
assertEquals("number", property4Schema.get("items").get("type").asText());
168+
169+
JsonNode property5Schema = propertiesSchema.get("property5");
170+
assertNotNull(property5Schema);
171+
assertEquals("string", property5Schema.get("type").asText());
172+
assertEquals(true, property5Schema.path("required").booleanValue());
173+
174+
JsonNode property6Schema = propertiesSchema.get("property6");
175+
assertNotNull(property6Schema);
176+
assertEquals("integer", property6Schema.get("type").asText());
177+
assertEquals(false, property6Schema.path("required").booleanValue());
165178
}
166179

167180
@JsonFilter("filteredBean")

0 commit comments

Comments
 (0)