Skip to content

Commit

Permalink
Fix #3742: from schemaType for LongSerializer (and `ShortSerializ…
Browse files Browse the repository at this point in the history
…er`) (#3743)
  • Loading branch information
cowtowncoder authored Jan 19, 2023
1 parent ae3ca88 commit abadc05
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project: jackson-databind
#3708: Seems like `java.nio.file.Path` is safe for Android API level 26
(contributed by @pjfanning)
#3736: Try to avoid auto-detecting Fields for Record types
#3742: schemaType of `LongSerializer` is wrong
(reported by @luozhenyu)

2.14.2 (not yet released)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static class ShortSerializer extends Base<Object> {
final static ShortSerializer instance = new ShortSerializer();

public ShortSerializer() {
super(Short.class, JsonParser.NumberType.INT, "number");
super(Short.class, JsonParser.NumberType.INT, "integer");
}

@Override
Expand Down Expand Up @@ -186,7 +186,7 @@ public void serialize(Object value, JsonGenerator gen,
@JacksonStdImpl
public static class LongSerializer extends Base<Object> {
public LongSerializer(Class<?> cls) {
super(cls, JsonParser.NumberType.LONG, "number");
super(cls, JsonParser.NumberType.LONG, "integer");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class SimpleBean
private Collection<Float> property4;
@JsonProperty(required=true)
private String property5;

public int getProperty1()
{
return property1;
Expand Down Expand Up @@ -80,10 +80,13 @@ public String getProperty5()
return property5;
}

public void setProperty5(String property5)
{
public void setProperty5(String property5) {
this.property5 = property5;
}

public long getProperty6() {
return 0L;
}
}

public class TrivialBean {
Expand Down Expand Up @@ -119,7 +122,7 @@ static class Numbers {
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper MAPPER = newJsonMapper();

/**
* tests generating json-schema stuff.
Expand Down Expand Up @@ -162,6 +165,16 @@ public void testOldSchemaGeneration() throws Exception
assertEquals("array", property4Schema.get("type").asText());
assertEquals(false, property4Schema.path("required").booleanValue());
assertEquals("number", property4Schema.get("items").get("type").asText());

JsonNode property5Schema = propertiesSchema.get("property5");
assertNotNull(property5Schema);
assertEquals("string", property5Schema.get("type").asText());
assertEquals(true, property5Schema.path("required").booleanValue());

JsonNode property6Schema = propertiesSchema.get("property6");
assertNotNull(property6Schema);
assertEquals("integer", property6Schema.get("type").asText());
assertEquals(false, property6Schema.path("required").booleanValue());
}

@JsonFilter("filteredBean")
Expand Down

0 comments on commit abadc05

Please sign in to comment.