Closed valasatava closed 5 years ago
Yes, you can directly access the ObjectMapper responsible for generating the schemes through SchemaWrapperFactory.MAPPER
. Be careful, though, to use JsonSchemaV4Factory
instead of JsonSchemaGeneratorV4
which is deprecated.
it doesn't seem to work with
SchemaWrapperFactory.MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
my interest in having a lower underscore case format in the resulting JSON schema.
Please, post your code so I can tell you better what to do.
Sorry it took me so long to provide more information. Here is my code:
JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory();
schemaFactory.setAutoPutDollarSchema(true);
JsonNode schema = schemaFactory.createSchema(Entry.class);
I'd linke to configure the mapper to use snake case naming strategy.
Where is your mapper?
If you're using JAX-RS with some Jackson integration, than you need to configure the mapper based on Jackson's jax-rs docs.
It's a simple Java application with dependences on Jackson libraries. I can create and configure the mapper but it seems that JsonSchemaV4Factory relies on it's own mapper internally. What's the mechanism to alter it's behavior?
I see. It seems Jackson converts only Java POJOs to configured case but doesn't behavior similarly with JsonNodes (and other objects).
JJSchema produces JsonNodes in camel case by default. The generated JsonNode should be converted to snake case manually or with some other library like guava or gson.
Please refer to this SO thread for a deeper explanation.
Thank you very much for you prompt responses and references. I'll proceed from there.
As a test execute the following code:
ObjectMapper MAPPER = new ObjectMapper();
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
ObjectNode node = MAPPER.createObjectNode();
node.put("camelCase", "test");
System.out.println(MAPPER.writeValueAsString(node));
and it will produce:
{"camelCase":"test"}
As we can see, Jackson didn't apply naming strategy to a generated JsonNode.
Is it possible to provide custom configuration for object mapper used for schema generation?