Use moshi with spring boot - spring

How do i use Moshi with Spring boot i have set the json mapper and added the pom but i don't seems to work
spring.http.converters.preferred-json-mapper=moshi
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi-adapters</artifactId>
<version>1.9.2</version>
</dependency>

Related

Spring boot (2.0.3) with Apache Ignite (2.7) Spring dependency conflict

I have integrated spring boot (2.0.3) with Apache ignite (2.7),while starting apache ignite in a embeded mode, It is throwing Null Pointer Exception while creating bean.
With the analysis, i was able to figure out the issue.
Spring boot (2.0.3) internally has dependency on spring (5.0.7) and Apache Ignite on spring (4.3.18).
while creating bean for ignite.cfg, apache ignite is referring the spring (5.0.7) due to priority in pom.xml and is throwing null pointer exception.
Solution I tried
1. I moved the ignite dependency at the begining of pom.xml just above spring boot dependency, that solved the ignite problem, but issues are getting created for spring boot (2.0.3 ) because of older spring(4.3.18) versions
please find the below pom
-----------------------------------------------------
<dependencies>
<!-- Apache Ignite For Cache -->
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.0.7.Final</version>
</dependency>
<!-- spring-boot web dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- spring-boot thymeleaf dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- spring-boot jpa dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.3.RELEASE</version>
<scope>test</scope>
</dependency>
-------------------------------------------------
I need suggestion on below points to tackle the above mentioned scenario.
1.Is apache ignite supports spring (5.x) versions, so that i can exclude dependency from apache-ignite and it can use spring dependency from spring boot ?
Or any other suggestions to tackle this isssue ?

How to map Cassandra Tuple collection in Java entity

I have a cassandra table with a set-of-tuple column as below,
ref_nums set<frozen<tuple<text,text>>>;
I want to map this into my Java entity. I am using spring-boot-starter-data-cassandra v2.0.4.RELEASE which leads to a driver version,
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.4.0</version>
How to map it?
What will be java entity configuration if I use UDT in place of tuple?
What is the difference between using UDT and using tuple?
This is the problem with built in dependency of spring boot.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
By the above configuration, we are replacing spring's own dependency of spring-data-cassandra (some previous version) and in addition to it we need spring-data-commons

override Thymeleaf in Spring Boot and can't find TemplateMode

I'm trying to override Thymeleaf in Spring Boot using the directions. However, my code needs to depend on org.thymeleaf.templatemode.TemplateMode except that class can't be found. How can I have both?
If you are using Spring 1.4.x or after you only need to add the spring-boot-starter-thymeleaf dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
If not, you may need to include these dependencies specifying the version as 3.0.0.RELEASE:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
And the parse of Html, in this case nekohtml:
<!-- Html5 Legacy Mode -->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
Then you should configure thymeleaf viewresolver, template engineand template resolver and Enable Web Mvc as well(Just add #EnableWebMvc to your configuration class).
So, the real answer is that the class TemplateMode is deprecated. I'm not sure how/why I was able to use it when depending on the thymeleaf library directly, but the solution was to substitute a string for the enum. (Be sure to use an uppercase string)

Springboot + spring data Mongo

I'm using in my Project the springboot 1.4.0.RELEASE and I put in my pom the next dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
so can I change this dependency to use the newest with no problem?
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.9.4.RELEASE</version>
</dependency>
I'm sure yes. These are the news in the 1.9:
The following annotations have been enabled to build own, composed annotations: #Document, #Id, #Field, #Indexed, #CompoundIndex,
#GeoSpatialIndexed, #TextIndexed, #Query, #Meta.
Support for Projections in repository query methods.
Support for Query by Example.
Out-of-the-box support for java.util.Currency in object mapping.
Add support for the bulk operations introduced in MongoDB 2.6.
Upgrade to Querydsl 4.
Assert compatibility with MongoDB 3.0 and MongoDB Java Driver 3.2 (see: MongoDB 3.0 Support).
You just exclude from spring-boot-starter-data-mongodb and overwritte it
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.9.4.RELEASE</version>
</dependency>

Spring JPA Hibernate and AttributeConverter

I have a small application (spring 4.0, jpa 2.1, hibernate 5.0.2) and had been using "old" java.util.Date* classes as well as java.sql.Date*. Now I wanted to use java.time instead and read that it would work with an AttributeConverter.
Unfortunately this doesn't seem to work. The moment I try to read the database object with a timestamp (the doa has an equivalent of java.time.localdatetime) I get an exception.
It seems the Converter isn't being used at all even though the annotation is there. I only have an applicationContext.xml and no persistence.xml so where would I tell jpa to use the Converter (if the annotation isn't enough)?
How can I see that the AttributeConverter is picked up by jpa at all?
Thanks in advance,
John.
#Converter is available in JPA2.1 .
Try to change your dependency config:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.2.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>

Resources