All Questions
Tagged with spring-boot json
2,518
questions
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:
"...
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 ...
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 ...
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....
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;
@...
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 ...
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....
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 ...
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 ...
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 ...
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....
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....
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 ...
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 {
...
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 ...
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 ...
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 ...
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-...
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 ...
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")
...
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 ...
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
...
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,"...
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) ...
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: [
{
... // ...
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 ...
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 ...
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 ...
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
{"...
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,...
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 ...
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
...
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-...
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",
...
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 ...
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 ...
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</...
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 ...
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 ...
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.
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....
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":...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...