Home Why spring rest controller return json not include nest object
Reply: 0

Why spring rest controller return json not include nest object

user2050 Published in July 16, 2018, 6:17 pm

I write a rest controller to get a list of objects form jpa repository, the Entity object is :

package com.khidi.alarm.domain

import com.fasterxml.jackson.annotation.JsonBackReference
import com.fasterxml.jackson.annotation.JsonIdentityInfo
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.ObjectIdGenerators
import io.swagger.annotations.ApiModelProperty
import java.util.*
import javax.persistence.*

@Table(name = "t_alarm_data")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator::class, property = "id")
class AlarmData(
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        var id: Long? = null, 
        var dataId: String? = null, 
        var location: String? = null,
        var locationId: String? = null,
        var sensorType:String? = null,
        var sensorName:String? = null,
        var sensorId:String? = null,
        var lng: Double? = null,
        var lat: Double? = null,
        var dataType: String = "Number",
        var numData: Double? = null,
        @ManyToOne(fetch = FetchType.EAGER)
        @JoinColumn(name = "alarmId")
        @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator::class, property = "id")
        var alarm: AlarmConf? = null,
        @JoinColumn(name = "ruleId")
        var rule: AlarmRule? = null


the controller requestmapping is :

@RequestMapping(value="allAlarmDatas", method = arrayOf(RequestMethod.GET), produces = arrayOf("application/x-spring-data-verbose+json"))
fun findAllAlarmData() :List<AlarmData> {
    var ret = alarmService.findAllAlarmData()
    return ret

when in debug mode, i can watch the alarm and rule field is not null,but the return json not include the two fields. I want to know how to include nest object in the json result. I write a pojo with nest object return ok, but the jpa entity object not return nested object.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309057 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO