Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ private static ObjectMapper createDefaultObjectMapper() {
return JsonMapper.builder()
// since version 4.32.0; pretty print by default (can be overridden by supplying explicit mapper)
.enable(SerializationFeature.INDENT_OUTPUT)
// since version 4.21.0
.enable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS)
// since version 4.25.0; as the above doesn't always work
.enable(JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
package com.github.victools.jsonschema.plugin.maven;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import jakarta.validation.constraints.Size;

@JsonClassDescription("Jackson annotation class")
public class TestClass {

@Size(min = 1)
private String name;
Comment on lines +24 to +26
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why this change in the scope of the Maven plugin?
It's not particular to that plugin, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default ObjectMapper is used internally by the Maven plugin implementation and cannot easily be overridden there. In the other modules, the default ObjectMapper is currently not used in production code—only in some unit tests. However, you're absolutely right: developers who use the generator module directly might rely on the default ObjectMapper for serialization and run into the same issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just another thought: From my perspective, the correct location for the tests depends on what the intended responsibility of the generator module actually is.

If the generator module is meant to produce an in-memory representation of a JSON Schema (i.e., a Jackson JsonNode tree), then the generator itself is not responsible for serialization. In that case, testing the serialized output does not belong in the generator module, because serialization is simply not part of its contract.
With this interpretation, the Maven plugin — which uses a concrete ObjectMapper configuration to produce schema files — is the right place to test the final serialized JSON output.

On the other hand, if the generator module were to expose public APIs that produce serialized schema output directly, or if serialization were considered part of its public contract, then serialization tests would naturally belong there.

Since I have not found any API in the generator module that produces a serialized form, I assumed that the module’s responsibility were limited to generating the schema object tree. Based on that interpretation, placing the serialization tests in the Maven plugin module seemed appropriate.


private int anInt;

public TestClass(int anInt) {
Expand All @@ -29,4 +34,8 @@ public TestClass(int anInt) {
public int getAnInt() {
return this.anInt;
}

public String getName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"object","properties":{"anInt":{"type":"integer"},"getAnInt()":{"type":"integer"}},"description":"Jackson annotation class","additionalProperties":false}
{"type":"object","properties":{"anInt":{"type":"integer"},"name":{"type":["string","null"]},"getAnInt()":{"type":"integer"},"getName()":{"type":["string","null"]}},"description":"Jackson annotation class","additionalProperties":false}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
},
"description" : "Jackson annotation class"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string",
"minLength" : 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"properties" : {
"anInt" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}
Loading