How can I enable the default Pascal package when using Jackson JSON in Spring MVC?

I have a project that uses Spring MVC to create and process multiple REST endpoints. I am currently working on using Jackson to automatically handle JSON serialization / deserialization using annotations @RequestBodyand @ResponseBody.

I got Jackson's job, so I have a starting point. My problem is that our old serialization was done manually and used by the Pascal body instead of the Camel body ("MyVariable" instead of "myVariable"), and Jackson makes the default Camel body.

I know that I can manually change the variable name using @JsonProperty. However, I do not believe that adding @JsonPropertyto all my variables is a viable long-term solution.

Is there a way to get Jackson to use the Pascal package when serializing and deserializing, other than using annotation @JsonProperty?

EDIT: There seems to be no clean way to do this from the outside. A couple of people suggested redefining different classes as a way to achieve my goal. I am open to suggestions that I can override what the case will change. At the moment, I have created a custom ObjectMapper that sets some properties that I want (namely Inclusion.NON_NULL). I have not yet found a place that would allow me to change the behavior of the casing string. Any thoughts?

+5
3

, (de). , :

1. BeanSerializerFactory.

_constructWriter(SerializationConfig config, TypeBindings typeContext, PropertyBuilder pb, boolean staticTyping, String name, AnnotatedMember propertyMember). name . Pascal, : String formattedName = name.substring(0, 1).toUpperCase() + name.substring(1);. name super._constructWriter.

2. BeanDeserializationFactory.

constructSettableProperty(DeserializationConfig config, BasicBeanDescription beanDesc, String name, AnnotatedMethod setter). name, BeanSerializerFactory.

3. ObjectMapper.

factory bean factory. ( : objectMapper.setDeserializerProvider(new StdDeserializerProvider(new CustomJacksonBeanDeserializerFactory()))).

. ObjectMapper JSON.

+1

, Jira issue ; . , , .

0

All Articles