#XmlTransient not working for Json - jersey

I am creating a simple API using Jersey Jax-Rs. I am using #XmlTransient to ignore the POJO being displayed in the output for a 1-to-many relationship. It works fine for XML output but the POJO gets displayed while outputting JSON. Do I need to add any dependency?
I am using the following dependency:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>

If you are using json-media-json-binding.jar , There is an annotation "#JsonbTransient" which helped me achieve this.

Related

WebClient create java.lang.ExceptionInInitializerError: null ExchangeStrategies.withDefaults

I'm trying to play around Spring WebFlux Webclient.
Tried to create a simple webclient in a quartz cron job
this.webClient = WebClient.create(this.queryUrl);
I made sure the queryUrl is valid.
However, I've got an error as following:
java.lang.ExceptionInInitializerError: null
at org.springframework.web.reactive.function.client.ExchangeStrategies.withDefaults(ExchangeStrategies.java:67)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeStrategies(DefaultWebClientBuilder.java:302)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:269)
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:154)
Tracing into the code, I've found that
DefaultExchangeStrategiesBuilder is null.
Does anyone have any idea what is missing?
It's a simple web client.
Thanks.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
Adding these dependencies and making sure the versions are the same.
I only had jackson-core before.
I tried to move the job out of quartz and ran it directly in main.
it still threw an exception, but it's different and I then looked it up
and some one has asked the issue and the solution to make sure both jackson packages need to be included and versions must be same.
I then added them to the pom file. try to run the job and it worked.
Putting the job back to quartz to run and it also worked.

406 HTTP response in REST springboot service (XML)

I'm new to springboot development and JAVA, I'll be needing your help.
I have created a REST service using springboot to accept and produce message of XML format.
I have generated JAVA class files for XSD schema using JAXB plugin.
I'm able to pass the XML request to the REST service and display the values as well, but in response of service i'm getting 406 HTTP response.
I tried checking stackoverflow for any hint, i found that adding below dependency in pom will resolve the issue. When i added below dependency then i was able to get the proper XML response but then i was unable to get the input XML in the service, i want getting "NULL" object as input to service after adding dependency
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
Can you please help me and let me know how can i pass input XML request and get output XML response as well. Currently either one of the case is working for me.
Thank you
I have resolved this issue by adding #XmlRootElement annotation in all the JAXB generated java class files.
Hope this will help someone!

How use java.time.LocalDate using Hibernate5 and Vaadin8?

I'm new on Vaadin and I'm trying to do a simple crud application.
I was starting from Vaadin CRUD sample; then I modify the backend project to use Hibernate and the ui project to manage the various tables.
I can do that for simple data type like varchar and int, now I would add a date's field but it returns me this error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '\xAC\xED\x00\x05sr\x00\x0Djava.time.Ser\x95]\x84\xBA\x1B"H\xB2\x0C\x00\x00xpw\x07\x03\x00\x00\x07\xE1\x06\x1Ax' for column 'data_nascita' at row 1
"DATA_NASCITA" is a date column on my mysql DB and the entity has a LocalDate linked to this field.
I found somewhere that this new java api is compatible only with Hibernate5 so in my pom file I add:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.1.0.Final</version>
</dependency>
and into the entity class I replace java.util.Date with java.time.LocalDate and delete the annotation #temporal.
The input class for this field is a DateField of Vaadin framework.
Which could be the problem?
P.S.: I'm blind, so I'm compiling the code with Netbeans8 but I modify the code with notepad++ so, if someone use the same technologies and hasn't any problem please tell me because I can't be sure that the problem is something with build process.
IF your hibernate version is greater than 5.2.+ you can just using column as below:
#Column
private LocalDate date;
Otherwise you need install hibernate-java8 module into your project.
On the other hand, you shouldn't install hibernate-java8 module into your project if the hibernate version >= 5.2, maybe it will makes some conflict, since the hibernate-java8 module is merged into hibernate.

Spring Data Projection not working

I want to use spring projection in my project. I am doing exactly as mentioned at this url http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections
interface NoAddresses {
String getFirstName();
String getLastName();
}
The only difference is my interface is public. and is not in the same package as the repository. Is that a requirement?
Still I see the whole entities are being returned, instead of just the projected columns.
I have
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.2.RELEASE</version>
</dependency>
Doesn't work. Do i need to add some dependency to make the projection work? I am not using spring-boot but just the spring-data stuff in my project, running on tomcat server.
thanks
Chahat

Jackson 2.4.2 Date serialization not milliseconds

I'm using Spring MVC 3.2.x with Jackson 2.4.2 for JSON web services.
I have objects that contain java.util.Date and the JSON contains a string representation of just the date portion: ("2014-09-15"). this goes against the Jackson documentation that says dates by default get marshalled as milliseconds epoch format (http://wiki.fasterxml.com/JacksonFAQDateHandling).
I would like the date members to be returned as milliseconds format, what am I missing here?
Here is my jackson libraries in my pom file:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.2</version>
</dependency>
I have annotation-driven in my applicationContext:
Thanks!
Alessandro Ferrucci
In my case, problem was in Spring Data REST(2.2.1) disabling WRITE_DATES_AS_TIMESTAMPS by default. I am sure Spring MVC might be doing the same, but I unable to locate that code-commit.
However I was able to locate code-commit in case of Spring Data REST:
DATAREST-336 - Default to ISO8601 date rendering
https://github.com/spring-projects/spring-data-rest/commit/2f1e9824cddb6085c9fd86f1e0b84721497669bb

Resources