从不受Spring Data-rest管理的控制器中返回Entity对象

时间:2018-08-20 12:20:14

标签: java spring spring-data-jpa spring-data-rest

我有一个Sub ReCalculate() Function Volatile() Application.Volatile End Function End Sub 实体及其Parent,如下所示

ParentRepository

@RepositoryRestResource(collectionResourceRel = "Parent", path = "parent") public interface ParentRepository extends PagingAndSortingRepository<Parent, Long>{ } 返回此输出

GET: /parent/10

我有一个{ "pid" : 10, "parentName" : "Parent 10", "_links" : { "self" : { "href" : "http://localhost:1111/app/api/v2/parent/10" }, "parent" : { "href" : "http://localhost:1111/app/api/v2/parent/10" }, "children" : { "href" : "http://localhost:1111/app/api/v2/parent/10/children" } } } 方法,如下所示:

@RestController

此方法应返回如下JSON:

@RequestMapping(value = "/getdummy")
    public Parent getdummy() {
        //Session session = em.unwrap(Session.class);
        //Parent parent=(Parent)session.get(Parent.class, new Long(10));
        Parent parent=new Parent();
        parent.setPid(new Long(1111));
        parent.setParentName("Parent name");
        Child c1=new Child();
        c1.setChildName("C1");
        c1.setChildKey(new Long(1234));
        c1.setParent(parent);
        Child c2=new Child();
        c2.setChildName("C2");
        c2.setChildKey(new Long(1235));
        c2.setParent(parent);
        List<Child> children=new ArrayList<>();
        children.add(c1);
        children.add(c2);
        parent.setChildren(children);

        return parent;

    }

但是我得到的是这个

{
    "pid": 1111,
    "parentName": "Parent name",
    "children": [{
        "childKey": 1234,
        "childName": "C1",
        "grandChildren": null
    },
    {
        "childKey": 1235,
        "childName": "C2",
        "grandChildren": null
    }]
}

我能够使它与spring数据其余部分一起使用的唯一方法是使用杰克逊的{ "pid" : 1111, "parentName" : "Parent name" }

Parent对象转换为String

我尝试从POM中排除spring数据剩余,并提供了预期的输出。如何从数据静态拦截器中排除特定的控制器/方法?

Source here

0 个答案:

没有答案