All Questions

Tagged with
Filter by
Sorted by
Tagged with
154 votes
17 answers
306k views

JSON Java 8 LocalDateTime format in Spring Boot

I'm having a small problem with formatting a Java 8 LocalDateTime in my Spring Boot Application. With 'normal' dates I have no problem, but the LocalDateTime fields are converted to the following: "...
Erik Pragt's user avatar
  • 14.2k
150 votes
10 answers
647k views

Returning JSON object as response in Spring Boot

I have a sample RestController in Spring Boot: @RestController @RequestMapping("/api") class MyRestController { @GetMapping(path = "/hello") public JSONObject sayHello() { return ...
iwekesi's user avatar
  • 2,306
118 votes
7 answers
187k views

JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value

I am new to Spring Data REST project and I am trying to create my first RESTful service. The task is simple, but I am stuck. I want to perform CRUD operations on a user data stored in an embedded ...
zavanton's user avatar
  • 1,454
107 votes
6 answers
345k views

Trying to use Spring Boot REST to Read JSON String from POST

Am using the latest version of Spring Boot to read in a sample JSON via Restful Web Service... Here's my pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache....
PacificNW_Lover's user avatar
106 votes
11 answers
47k views

Spring boot @ResponseBody doesn't serialize entity id

Have a strange problem and can't figure out how to deal with it. Have simple POJO: @Entity @Table(name = "persons") public class Person { @Id @GeneratedValue private Long id; @...
Konstantin's user avatar
  • 1,077
64 votes
9 answers
223k views

Deserialize Java 8 LocalDateTime with JacksonMapper

I have read several questions with answers here in SO concerning serialization and deserialization between java.time.LocalDateTime and JSON property but I can't seem to get it working. I have managed ...
Smajl's user avatar
  • 7,743
61 votes
3 answers
61k views

Modify default JSON error response from Spring Boot Rest Controller

Currently the error response from spring boot contains the standard content like below: { "timestamp" : 1426615606, "exception" : "org.springframework.web.bind....
Marco's user avatar
  • 15.6k
48 votes
5 answers
64k views

Jackson serializes a ZonedDateTime wrongly in Spring Boot

I have a simple application with Spring Boot and Jetty. I have a simple controller returning an object which has a Java 8 ZonedDateTime: public class Device { // ... private ZonedDateTime ...
jbx's user avatar
  • 21.8k
39 votes
14 answers
87k views

Could not write JSON: Infinite recursion (StackOverflowError); nested exception spring boot

This is my District Controller, when I try to fetch data after saving I get the error, even when I try get object form getDistrict(Long id) the same strikes please suggest some way, am very new at ...
Bikash Dhal's user avatar
35 votes
12 answers
78k views

Spring boot 404 error custom error response ReST

I'm using Spring boot for hosting a REST API. Instead of having the standard error response I would like to always send a JSON response even if a browser is accessing the URL and as well a custom data ...
Markus's user avatar
  • 961
33 votes
16 answers
44k views

Pretty print JSON output of Spring Boot Actuator endpoints

Spring Boot Actuator provides several endpoints to monitor an application as: /metrics /beans /health ... Checking the endpoints with: curl http://localhost:8080/metrics results in: {"counter....
Bernhard Woditschka's user avatar
33 votes
3 answers
111k views

Getting not supported media type error

Hi i am using Rest client i.e Postman to send the REST request but getting error : { "timestamp": 1432829209385, "status": 415, "error": "Unsupported Media Type", "exception": "org....
Qasim's user avatar
  • 9,388
33 votes
5 answers
58k views

Jackson @JsonFormat set date with one day less

I have been used Spring Date Rest with Spring Boot in my project. This project has a object and I have used the annotation @JsonFormat to format the date field that will be received from my Json. The ...
William Miranda's user avatar
31 votes
2 answers
73k views

Springboot - validate @RequestBody

Question: It is possible to validate the JSON payload of a request body, without specifically writing if statements? Maybe via annotation or configuration? I have a very easy POJO: public class Foo { ...
PatPanda's user avatar
  • 4,262
25 votes
5 answers
88k views

How to send the Multipart file and json data to spring boot

I have the POST request api call to accept the json body request parameters and multipart file from client side(postman or java client). I want to pass both the json data and multipart file in single ...
DIVA's user avatar
  • 569
23 votes
1 answer
64k views

Best way to load some JSON files into a Spring Boot application

I'm about to create a Rest webservice application, and I need to load all JSON files that exist in a folder passed as parameter (in application.yml a priori), on application startup, to use them later ...
diamah's user avatar
  • 333
22 votes
1 answer
16k views

When does Jackson require no-arg constructor for deserialization?

In my spring boot project, I noticed a strange Jackson behavior. I searched over internet, found out what to do, but haven't found out why. UserDto: @Setter @Getter @AllArgsConstructor public class ...
ayfkly's user avatar
  • 271
21 votes
5 answers
11k views

While using Spring Data Rest after migrating an app to Spring Boot, I have observed that entity properties with @Id are no longer marshalled to JSON

This question is related to this SO question (Spring boot @ResponseBody doesn't serialize entity id). I have observed that after migrating an app to Spring Boot and using the spring-boot-starter-...
Patrick Grimard's user avatar
21 votes
3 answers
17k views

How to dynamically ignore a property on Jackson serialization

I have an entity with multiple @ManyToOne associations. I am using spring-boot to expose a REST API. Currently, I have multiple REST API's which return a JSON response of the whole entity, including ...
Achaius's user avatar
  • 6,054
20 votes
1 answer
87k views

Jackson Converting String to Object

Link.java @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ "rel", "href","method" }) public class Link { @JsonProperty("rel") private String rel; @JsonProperty("href") ...
ytibrewala's user avatar
  • 1,087
19 votes
1 answer
25k views

Create a JSON object to post in Spring Boot tests

I want to write basic test to execute a POST request on a /users URL with JSON payload to create a user. I cannot find how to convert a new object to JSON, and so far have this much, it's obviously ...
Maciej Szlosarczyk's user avatar
19 votes
5 answers
39k views

ERROR: column is of type json but expression is of type character varying in Hibernate

I need to map two columns of entity class as json in postgres using spring data jpa. After reading multiple stackoverflow posts and baeldung post , How to map a map JSON column to Java Object with JPA ...
user2800089's user avatar
  • 2,207
19 votes
8 answers
32k views

Spring REST, JSON "Can not handle managed/back reference 'defaultReference'" 415 Unsupported Media Type

I am trying to POST to http://localhost:9095/translators from an AngularJS front-end using Spring boot/Spring RestController backend. I can do a GET and the response is like following: [{"userId":1,"...
senseiwu's user avatar
  • 5,149
19 votes
6 answers
57k views

How to throw an exception back in JSON in Spring Boot

I have a Request Mapping - @RequestMapping("/fetchErrorMessages") public @ResponseBody int fetchErrorMessages(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime) ...
Prateek Narendra's user avatar
19 votes
4 answers
19k views

Spring Boot: Wrapping JSON response in dynamic parent objects

I have a REST API specification that talks with back-end microservices, which return the following values: On "collections" responses (e.g. GET /users) : { users: [ { ... // ...
filpa's user avatar
  • 3,610
18 votes
6 answers
17k views

Force Milliseconds When Serializing Instant to ISO8601 using Jackson

I have some questions related to JSON serialization using Jackson in a project where I use Spring Boot 2.0.0.M6, Spring Framework 5.0.1.RELEASE and Jackson 2.9.2. I have configured the following ...
André Gasser's user avatar
18 votes
2 answers
31k views

Spring Boot - Encrypt JSON data

In our application we have to encrypt/decrypt the Json property values (not the property name) for each request and response. Example, {"userName":"encrypted value", "email":"encrypted value"} We ...
Raj's user avatar
  • 395
18 votes
4 answers
12k views

How to include JSON response body in Spring Boot Actuator's Trace?

Spring Boot Actuator's Trace does a good job of capturing input/output HTTP params, headers, users, etc. I'd like to expand it to also capture the body of the HTTP response, that way I can have a full ...
SergeyB's user avatar
  • 9,732
17 votes
3 answers
25k views

Make JSON payload fields case insensitive when mapping to Java Object in REST API developed using SpringBoot

I am working on REST API developed using SpringBoot application. Here I want to make the fields in the payload(JSON) as case insensitive when mapping to a Java Object. Below is my code. Payload {"...
Rakesh Gourineni's user avatar
17 votes
4 answers
72k views

Spring default consumes and produces

I'm writing a servlet that will use a bunch of RestControllers to provide functionality. All of that will use JSON almost exclusively, so I would like a compact way to say: Unless specified otherwise,...
Senshi's user avatar
  • 383
17 votes
3 answers
16k views

Spring REST Controller returns JSON with empty data [closed]

I have a simple Spring Boot web application. I'm trying to receive some data from server. The Controller returns a collection, but the browser receives empty JSON - the number of curly brackets is ...
Radziasss's user avatar
  • 193
16 votes
5 answers
30k views

How can a store raw JSON in Mongo using Spring Boot

I'd like to take HTTP PUT request with JSON and store it unmodified in Mongo. How can I do this? The best I have is this: @RestController public class ConfigurationController { @Autowired ...
user2732949's user avatar
  • 1,203
15 votes
6 answers
52k views

Spring Boot LocalDate field serialization and deserialization

In Spring Boot 1.2.3.RELEASE with fasterxml what is the correct way of serializing and de-serializing a LocalDate field to ISO date formatted string? I've tried: spring.jackson.serialization.write-...
aycanadal's user avatar
  • 1,136
15 votes
2 answers
33k views

How to rename json objects(variables) name in spring boot

Hello I am new to spring boot and JSON and need help in renaming the variable name coming in response. Consider this as a input "1": { "id": "1", "firstName": "Cdgdghirayu", ...
Chirayu Singhvi's user avatar
15 votes
1 answer
9k views

JSON parse error: Already had POJO for id

I already saw some question about this topic but i could not apply it to my case because I tried to apply them and the error continued. so I come to expose my situation. I read some comments about ...
Eduardo Krakhecke's user avatar
14 votes
1 answer
21k views

How to format the json date format using spring boot

I am working on spring boot and gradle for creating a rest service. Now I need to format the json date in the form of "yyyy-MM-dd", i.e, the format should be dateOfBirth: "16-03-2015", but I am ...
Pramod's user avatar
  • 731
13 votes
2 answers
70k views

Spring Boot Automatic JSON to Object at Controller

I have SpringBoot application with that dependencies: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</...
kamaci's user avatar
  • 73.9k
13 votes
2 answers
32k views

spring boot rabbitmq MappingJackson2MessageConverter custom object conversion

I'm trying to create a simple spring boot app with spring boot that "produce" messages to a rabbitmq exchange/queue and another sample spring boot app that "consume" these messages. So I have two apps ...
Gustavo's user avatar
  • 556
13 votes
2 answers
28k views

How to handle JSON Parse Error in Spring Rest Web Service

I have a rest web service developed with Spring Boot.I am able to handle all the exceptions that occur due to my code, but suppose the json object that the client posts is not compatible with the ...
T Anna's user avatar
  • 944
13 votes
3 answers
39k views

What is use of the annotation @JsonIgnore?

I'm joining tables with one to many cardinality, the classes I'm using refer to each other. And I'm using @JsonIgnore annotation with out understanding it deeply.
yafiet andebrhan's user avatar
13 votes
2 answers
9k views

Jackson fails on deserializing String to Joda-Time

I'm using Spring Boot 1.5.6 with Jackson 2.8.8. When deserializing the answer of a REST call, Jackson fails with the following exception: JSON parse error: Can not construct instance of org.joda....
Tom's user avatar
  • 4,007
13 votes
3 answers
10k views

Spring MVC (or Spring Boot). Custom JSON response for security related exceptions like 401 Unauthorized or 403 Forbidden)

I am developing a REST service. It uses JSON and must return some predefined JSON object in case of a problems. The default Spring response looks like this: { "timestamp": 1512578593776, "status":...
30thh's user avatar
  • 11k
12 votes
3 answers
14k views

How to skip Optional.empty fields during Jackson serialization?

I have a Java class with an Optional field. I am serializing the class to JSON using Jackson 2.8.3 (called from Spring web 4.3.3). I am hoping to get the serializer to skip the field if the Optional ...
André Risnes's user avatar
12 votes
2 answers
8k views

MockMvc HttpMediaTypeNotSupportedException: Content type 'application/json' not supported

I receive the following exception: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json' not supported at org.springframework.web.bind.annotation.support....
dinamix's user avatar
  • 651
12 votes
1 answer
15k views

Accept arbitrary JSON as RequestBody in Spring

As the title suggests, I'd like my controller class to accept (mostly) arbitrary JSON in the RequestBody as part of a POST. Before you ask why I'd want unworkable JSON, it's because the JSON is simply ...
J_Stan's user avatar
  • 503
12 votes
1 answer
19k views

How to test json structure in spring boot

I found this code to test if a json string is equal to another string @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc public class MockMvcExampleTests { @Autowired private ...
user avatar
12 votes
3 answers
24k views

how modify the response body with java filter?

I want to perform some filter logic to HTTP responses (which are in json format). I had successfully change the response body, but when the (string) size of the body changes: I am getting missing the ...
JaimeRG's user avatar
  • 231
12 votes
3 answers
9k views

LocalDate is serialized as an array

I'm using springBoot to develop a REST APi. And i have a LocalDate field "firstDate" in the response model of a GET endpoint. But this LocalDate is serializable as an array in the response's ...
Rubis's user avatar
  • 121
11 votes
2 answers
12k views

Spring boot JPA - JSON without nested object with OneToMany relation

I have a project which deals with some ORM mapping of objects (there are some @OneToMany relations etc). I am using REST interface to treat these objects and Spring JPA to manage them in the API. ...
Smajl's user avatar
  • 7,743
11 votes
4 answers
14k views

Spring Boot, Spring MVC JSON RequestBody: Unknown property ignored

we are developing a JSON web service to receive data via the @RequestBody annotation. In case a property is included in the request that does not match with the deserialized bean, we expect an HTTP ...
user152468's user avatar
  • 3,212

1
2 3 4 5
51