Mapstruct randomly generating setters - java

I recently discovered Mapstruct and something quite weird is happening. Almost every single time, new implementation of mapper is generating and sometimes is with/without getters and setters. After some research I still can't find a issue with that.
As all of the dependencies, as well as proper annotation paths are in
pom.xml
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.2.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.2.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.1.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
#Mapper(componentModel = "spring")
public interface MessageMapper {
MessageEntity messageDtoToEntity(MessageDTO messageDTO);
MessageDTO messageEntityToDto(MessageEntity messageEntity);
}
#Getter
#Setter
#Entity
#Table(name = "messages")
#NoArgsConstructor
#AllArgsConstructor
#Builder
public class MessageEntity {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Setter(AccessLevel.NONE)
private Long id;
#Column(name = "message", nullable = false)
private String message;
public static MessageEntity createMessageEntityWithName(String message) {
MessageEntity mes = new MessageEntity();
mes.setMessage(message);
return mes;
}
}
#NoArgsConstructor
#Getter
#Setter
public class MessageDTO {
#NotNull(message = "Field message has to be provided")
private String message;
public static MessageDTO create(String message) {
MessageDTO mes = new MessageDTO();
mes.setMessage(message);
return mes;
}
}
#Component
public class MessageMapperImpl implements MessageMapper {
#Override
public MessageEntity messageDtoToEntity(MessageDTO messageDTO) {
if ( messageDTO == null ) {
return null;
}
MessageEntity messageEntity = new MessageEntity();
return messageEntity;
}
#Override
public MessageDTO messageEntityToDto(MessageEntity messageEntity) {
if ( messageEntity == null ) {
return null;
}
MessageDTO messageDTO = new MessageDTO();
return messageDTO;
}
}

The reason why this is not working is because the annotationProcessorPaths is configured on the spring-boot-maven-plugin. The annotationProcessorPaths needs to be configured on the maven-compiler-plugin and then the annotation processors will properly be used (including the lombok-mapstruct-binding.

Related

Spring wont deserialize Object when content is Application/JSON

I am try to create an endpoint in spring where I sent raw JSON and it will not deserialize to object but if I use form Data it works fine. I am just wondering what I did wrong?
this is the object
#Document("Boats")
#NoArgsConstructor
#AllArgsConstructor
#Getter
#Setter
public class Boat{
#Id
private String id;
private Boolean online;
private String boatName;
private String lastOnline;
private String password;
#JsonIgnore
#Transient
private java.net.InetAddress inetAddress;
private String displayAddress;
private String displayStatus;
public Boat(String boatName, InetAddress inetAddress,Boolean online) {
this.online = online;
this.boatName = boatName;
this.inetAddress = inetAddress;
this.displayAddress = inetAddress.getHostAddress();
if(online){
String pattern = "E, dd MMM yyyy HH:mm:ss z";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("CST"));
this.lastOnline = simpleDateFormat.format(new Date());
}
updateDisplayStatus();
}
public void updateDisplayStatus(){
if(getOnline()){
setDisplayStatus(BoatStatus.ONLINE.getDisplayText());
}else{
setDisplayStatus(BoatStatus.OFFLINE.getDisplayText());
}
}
}
and this is the endpoint
#PostMapping(path= "/boat/update")
public ResponseEntity updateBoat(#RequestBody Boat boat){
boatFacade.updateBoat(boat);
return ResponseEntity.ok().build();
}
this is the body of the request
{
"id":"62ca4f7c5a3e0f1411445065",
"online":"false",
"boatName":"dfsjkdfsd",
"lastOnline":"null",
"password":"null",
"displayAddress":"10.50.50.50",
"displayStatus":"ONLINE"
}
these are the POM dependencies I am using not sure if I am missing
a dependency
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
It is always recommended to specify the Type/Kind of data that your endpoint consume/produce.
#PostMapping(value = "/boat/update", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Object reserializes - debug Point
PostMan Setting

RESTful API, Jersey, POST request 415 Unsupported Media Type

I am new to RESTful services and jersey. I am trying to send a POST request (using postman) for this function.
#Path("/bikes")
public class BikesResource {
#POST
#Consumes ({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public void createBike(Bike bike) {
BikeDao.instance.getModel().put(bike.getBikeID(),bike);
}
This is my Bike Class:
#XmlRootElement
public class Bike {
private String bikeID;
private String ownerName;
private String color;
private String gender;
public Bike(){
}
public Bike(String bikeID, String ownerName, String color, String gender){
this.bikeID = bikeID;
this.ownerName = ownerName;
this.color = color;
this.gender = gender;
}
public String getBikeDetails(){
return getBikeID() + ", " + getOwnerName() + ", " + getColour() + ", " + getGender();
}
public String getBikeID(){
return bikeID;
}
public String getOwnerName(){
return ownerName;
}
public String getColour(){
return color;
}
public String getGender(){
return gender;
}
public void setBikeID(String bikeID){
this.bikeID = bikeID;
}
public void setOwnerName(String ownerName){
this.ownerName = ownerName;
}
public void setColour(String colour){
this.color = colour;
}
public void setGender(String gender){
this.gender = gender;
}
}
The postman request looks like this:
[1]: https://i.stack.imgur.com/N5US9.png
However I get 415 Unsupported Media type and I don't know why. I was thinking that maybe there is something wrong with my pom.xml, but I can't figure it out.
This is the pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.utwente.di</groupId>
<artifactId>bikeDealer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</project>
I would really appreciate some help. Thank you!
It looks like you don't have JSON/XML Jersey modules to support the media you listed in #Consumes.
Check this doc: https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/media.html#json
and try:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.30.1</version>
</dependency>
(or better, use BOM to lock Jersey versions)
Did you check if in Postman's 'Headers' section the ContentType is specified as 'application/json'? That indicates that the payload is in JSON format. If it's missing it throws error 415.

Java JsonIgnore is not hiding field

Need to hide one field from Json, but leave it, because need to use it in another method ( get ). Tried to do it, but id field is still visible in Json. Whats wrong here?
Dependencies:
<properties>
<!-- Use the latest version whenever possible. -->
<jackson.version>2.4.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.53</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri -->
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.31</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
Trying to do it this way:
package test.model;
import java.math.BigDecimal;
import test.model.DbTest;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
#JsonIgnoreProperties(value = { "id" })
public final class Home {
#JsonIgnore
private final BigDecimal id;
private final String date;
public Home( //
BigDecimal id, //
String date) {
this.id = id;
this.date = date;
}
public final BigDecimal getId() {
return id;
}
public final String getDate() {
return date;
}
public static final Home newInstance(
DbTest test) {
return new Home(
test.getId(),
test.getDate());
}
}
Try using this in pom.xml
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.4</version>
</dependency>
or remove 'final' from field

Jersey: 500 Internal Error While trying to return XML Data using jersey java framework

Hi Someone help I'm trying to find the bug for past 24hrs. I'm newbie to jersey framework so please help me to clear the error.
The error is:
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=java.util.List<org.example.model.Helloworld>.
The files that I'm using are:
HelloworldResources.java
package org.example.resources;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.example.model.Helloworld;
import org.example.service.HelloworldService;
import java.util.List;
#Path("/helloworld")
public class HelloworldResources {
HelloworldService helloworldService = new HelloworldService();
#GET
#Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
public List<Helloworld> getMessage(){
System.out.println(helloworldService.getMessages());
return helloworldService.getMessages();
}
}
Helloworld.java
package org.example.model;
import javax.xml.bind.annotation.*;
#XmlRootElement(name = "helloworld")
public class Helloworld {
private Long id;
private String name;
public Helloworld() {
}
public Helloworld(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
HelloworldServices.java
package org.example.service;
import org.example.model.Helloworld;
import java.util.ArrayList;
import java.util.List;
public class HelloworldService {
public List<Helloworld> getMessages(){
List<Helloworld> list = new ArrayList<>();
Helloworld h1 = new Helloworld(1L, "Ar");
Helloworld h2 = new Helloworld(2L, "Aravind");
list.add(h1);
list.add(h2);
return list;
}
}
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>JerseyHelloworld2</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>JerseyHelloworld2</name>
<build>
<finalName>JerseyHelloworld2</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0-b170201.1204</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0-b170127.1453</version>
</dependency>
</dependencies>
<properties>
<jersey.version>3.0.2</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
These are total files that i'm using
Server: apache tomcat 10.0.6

Java Spring - 415 Unsupported Media Type

Here is my Controller:
#RestController
public class UserController {
#RequestMapping(value = "/test", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public User someName(#RequestBody User user){
System.out.println(user.toString());
return user;
}
}
User class:
#Entity
#Table(name = "user")
public class User {
#Id #GeneratedValue
#Column(name = "id")
private Integer id;
private String name;
private String secondname;
private String email;
public User() {
}
public User(Integer id, String name, String secondname, String email) {
this.id = id;
this.name = name;
this.secondname = secondname;
this.email = email;
}
public User(String name, String secondname, String email) {
this.name = name;
this.secondname = secondname;
this.email = email;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
#Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Column(name = "secondname")
public String getSecondname() {
return secondname;
}
public void setSecondname(String secondname) {
this.secondname = secondname;
}
#Column(name = "email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#Override
public String toString() {
return new StringBuilder().append(this.name).append(", ").append(this.secondname).append(", ")
.append(this.email).toString();
}
}
And my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl</groupId>
<artifactId>javalab</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>javalab Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.7</java-version>
</properties>
<repositories>
<!-- Repository for ORACLE JDBC Driver -->
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Servlet API -->
<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- Jstl for jsp page -->
<!-- http://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSP API -->
<!-- http://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!-- Spring dependencies -->
<!-- http://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- Hibernate -->
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.8.Final</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.8.Final</version>
</dependency>
<!-- MySQL JDBC driver -->
<!-- http://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<!-- Oracle JDBC driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<!-- SQLServer JDBC driver (JTDS) -->
<!-- http://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Mail Start -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- Mail End -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>
</dependencies>
<build>
<finalName>javalab</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
</project>
When I want to post in in postman:
{
"name": "test",
"secondname": "test",
"email": "test#test.pl"
}
I have an error: 415 Unsupported Media type
More precisely I have: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
In postman I choose raw and JSON (application/json). As headers I have written: Content-Type as key and application/json as value.
Somebody have any idea what I'm doing wrong?
You can use the chrome's inspect to see the HTTP header of your postman's request.Check whether the content-Type is corrent.
This is so common in spring. Make your entity serializable.

Categories