gpt4 book ai didi

Spring 数据休息 : removing _links attributes from the response of a hypermedia Rest JPA entities

转载 作者:行者123 更新时间:2023-12-04 11:13:50 28 4
gpt4 key购买 nike

我想自定义超媒体 Rest JPA 实体的响应,并想删除所有 _links 属性和自链接属性。
我的客户端应用程序并不大,它知道要调用的确切 REST API。所以我觉得这些在 HTTP 数据包中传输的额外字节在我的应用程序中总是一个开销。

那么如何才能从响应中删除此链接属性呢?

现在 REST API 响应是:

{
"_embedded" : {
"questionsTypes" : [ {
"queTypeID" : 2,
"queDescription" : "Single choice rating selection",
"_links" : {
"self" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType/2"
},
"questionsType" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType/2{?projection}",
"templated" : true
}
}
},{
"queTypeID" : 5,
"queDescription" : "Subjective questions",
"_links" : {
"self" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType/5"
},
"questionsType" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType/5{?projection}",
"templated" : true
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType"
},
"profile" : {
"href" : "http://localhost:8080/question_web/rest/profile/QuestionsType"
},
"search" : {
"href" : "http://localhost:8080/question_web/rest/QuestionsType/search"
}
}
}

我期望的最终回应是这样的:
{
"_embedded" : {
"questionsTypes" : [ {
"queTypeID" : 2,
"queDescription" : "Single choice rating selection",
},{
"queTypeID" : 5,
"queDescription" : "Subjective questions",
} ]
}
}

最佳答案

@Component
public class MyEntityProcessor implements RepresentationModelProcessor<EntityModel<MyEntity>> {

@Override
public EntityModel<MyEntity> process(EntityModel<MyEntity> model) {
return EntityModel.of(model.getContent());
}

}

关于 Spring 数据休息 : removing _links attributes from the response of a hypermedia Rest JPA entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39433044/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com