I write a rest spring boot that return List<Map<String,Object>> as response.
public List<Map<String,Object>> getAll(@Valid DataRequestDto dto)
{
List<Map<String,Object>> data = (List<Map<String, Object>>) dataOperationMap.getAllData(dto);
return data;
}
An example of expected output is as follow:
{
"id": 7581,
"serialid": 24,
"parentid": 7576,
"rowno": 5,
"code": "15005",
"acckind": {
"id": 10080001,
"title": "بودجه ای",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": ""
},
"accbalance": {
"id": 10160001,
"title": "خنثی و بدون کنترل",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": null
}
},
{
"id": 7582,
"serialid": 24,
"parentid": 7576,
"rowno": 6,
"code": "15006",
"acckind": {
"id": 10080001,
"title": "بودجه ای",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": ""
},
"accbalance": {
"id": 10160001,
"title": "خنثی و بدون کنترل",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": null
}
}
but "accKind" and "accBalance" From the second data onwards, have been replaced by id only, as follow:
{
"id": 7581,
"serialid": 24,
"parentid": 7576,
"rowno": 5,
"code": "15005",
"acckind": {
"id": 10080001,
"title": "بودجه ای",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": ""
},
"accbalance": {
"id": 10160001,
"title": "خنثی و بدون کنترل",
"systemDefine": 1,
"typeValueId": 1,
"isActive": true,
"isDefault": true,
"engTitle": null
}
},
{
"id": 7582,
"serialid": 24,
"parentid": 7576,
"rowno": 6,
"code": "15006",
"acckind": 10080001,
"accbalance": 10160001,
}
I want the whole object to be displayed in all the list data.
in debug I understood that the data is correct until it is returned, and it is changed in the conversion to json.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hushaerp</groupId>
<artifactId>form-manager</artifactId>
<version>1.0-RELEASE</version>
<name>form-manager</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</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-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-config</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The reason for this problem was that when adding the Map Entries, I put the same objects of acckind and accbalance in each entry, in case they needed to be new for each entry and get a new id.