Spring - How do I annotate properties in classes - spring

I have a Java RESTful client that works create and I use Jackson to de/serialize the returned requests (serialize as XML).
For returned classes I don't need to do anything. For the classes I post (serialize) I use com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
Now with Spring, where the inbound requests can be JSON or XML and the return also can be JSON or XML, do I need to do the equivalent? And if so, what annotation do I use?
Spring pulls in Jackson. But the library it pulls in has com.fasterxml.jackson but not com.fasterxml.jackson.dataformat.
And... I was not aware there were different Jackson libraries. But as there are, which one does Spring use?

Related

The relationship between spring-web and spring-webmvc

I found #Controller and #GetMapping in spring-web, but only use these two annotations, not using DispatcherServlet how to receive requests, why these two annotations are not placed in spring-webmvc
Many use Spring Boot for building REST-APIs, and then consume those APIs from other backend services or JavaScript based web GUIs. In that case you want the Spring Web package to be able to create your controller's but don't need the MVC parts. That's why they have put the MVC parts in its own package.

Spring vs JAX-RS

Here, several questions have been asked by many developers about difference between Spring-Rest and JAX-RS.
And, I have also learned that Spring is not following any specification and Spring framework has their own implementation then
Why Spring allows all that Annotations which are supported/used by JAX-RS by default?
Spring does not support JAX-RS annotations. If there is a situation where you think they do, then you are mistaken or it's just a coincidence. Period. If you will add any JAX-RS annotations in my Spring MVC program, nothing will happen. Annotations are just metadata. They are not programs. If Spring does not recognize the metadata, it will ignore it. But if you use a JAX-RS annotation in place of a Spring annotation that is used for the same purpose, respective of their framework, then you will not get the expected Spring behavior. So basically, if you are using Spring MVC, remove any JAX-RS dependencies so you don't mistakenly use them.

thymeleaf vs thymeleaf-spring4 dependency

Question is simple, what is the difference between the above dependencies? Does the first one enough for a springboot app or the second contains something special?
Artifact thymeleaf is the Core library.
Artifact thymeleaf-spring4 allows to integrate Thymeleaf with the Spring Framework, especially (but not only) Spring MVC. Btw there are several Thymeleaf integration packages for different Spring versions are available at the moment:
thymeleaf-spring3, thymeleaf-spring4, thymeleaf-spring5.
Information from thymeleaf-spring official documentation:
Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.
These integrations will allow you to:
Make the mapped methods in your Spring MVC #Controller objects forward to templates managed by Thymeleaf, exactly like you do with JSPs.
Use Spring Expression Language (Spring EL) instead of OGNL in your templates.
Create forms in your templates that are completely integrated with your form-backing beans and result bindings, including the use of property editors, conversion services and validation error handling.
Display internationalization messages from message files managed by Spring (through the usual MessageSource objects).
Resolve your templates using Spring’s own resource resolution mechanisms.
If you use Spring Boot, you can just use the spring-boot-starter-thymeleaf dependency. It already contains the above two dependencies as well as some others.

How do i force spring-boot to use jaxb?

We have some xml that uses capitol letters for all fields. Spring boot automatically uses jackson which does not work well with this. I have the xml "jaxb"d into java objects that tell it to use the capitol letters. However spring always seems to use Jackson.
Anyway to force it to use Jaxb?
You can find here a list of commonly used in spring-boot properties for your application.properties file. You probably need:
spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE
Here are the available naming strategies for Jackson.
If you insist on Jaxb I believe it will be used by spring boot unless you include jackson-dataformat-xml in your classpath (may have to exclude it).

Exposing Contract first SOAP Webservice with spring-boot and Weblogic

I am trying to expose Contract First SOAP Webservice with spring-boot and Weblogic. Its a Gradle based setup and i am using following dependencies for generation of JAXB classes.
jaxb 'com.sun.xml.bind:jaxb-core:2.2.11'
jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.11'
jaxb 'com.sun.xml.bind:jaxb-impl:2.2.11'
jaxb 'javax.xml.bind:jaxb-api:2.2.12-b141001.1542'
compile(files(genJaxb.classesDir).builtBy(genJaxb))
I have a static response XML which i am sending as a response. The XML is first unmarshalled and then return. Now the problem here is response XML elements are coming with namespace prefixes which i want to avoid as on the client side it is causing some issue which i am not aware of as i dont have access to that system.
Could you please suggest on how i can control marshalling process used by Spring framework to avoid the prefix generation?
Thanks and Regards,
HG

Resources