小编Ven*_*nky的帖子

Json自定义解串器陷入无限递归

通过以下方式实现了自定义反序列化器以反序列化JSON。但是mapper.treeToValue导致无限次调用代码。

public class MyDeserializer extends StdDeserializer<MyResource>  {
       @Override
    public myResourcedeserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
         MyResource resource = null;
        Class<? extends MyResource > clazz = null;
        ObjectMapper mapper = (ObjectMapper) parser.getCodec();
        ObjectNode node = (ObjectNode) mapper.readTree(parser);

        Iterator<Map.Entry<String, JsonNode>> elementsIterator = node.fields();

        while (elementsIterator.hasNext()) {
            Map.Entry<String, JsonNode> element = elementsIterator.next();
            if(element.getKey().equals("typeId"))
            {
                if(element.getValue().asInt() == 1)
                {
                    clazz = SpecificResource.class;
                    break;
                }
            }
        }
        return  mapper.treeToValue(node,clazz);
}
Run Code Online (Sandbox Code Playgroud)

执行mapper.treeToValue之后,控件再次返回myResourcedeserialize方法,并无限执行该方法,并导致stackOverFlowError。

有什么建议吗?

java json jackson deserialization

5
推荐指数
1
解决办法
662
查看次数

在休眠状态下映射PostgreSQL LTREE列时出现错误

我试图按如下方式映射休眠状态下的postgresql ltree列:

在实体中:

private String path;

@Column(name="org_path", columnDefinition="ltree")
public String getPath() {
   return path;
Run Code Online (Sandbox Code Playgroud)

表结构:

CREATE TABLE relationship (
    relationship_id int4 NOT NULL,
    parent_organization_id uuid NOT NULL,
    child_organization_id uuid NOT NULL,
    org_path ltree NOT NULL,
    CONSTRAINT relationship_pk PRIMARY KEY (relationship_id),
    CONSTRAINT organization_fk3 FOREIGN KEY (parent_organization_id) REFERENCES organization(organization_id) ON DELETE RESTRICT ON UPDATE RESTRICT,
    CONSTRAINT organization_fk4 FOREIGN KEY (child_organization_id) REFERENCES  organization(organization_id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

wrong column type encountered in column [org_path] in table [relationship]; found [“schemaName"."ltree" …
Run Code Online (Sandbox Code Playgroud)

java postgresql entity hibernate ltree

1
推荐指数
1
解决办法
964
查看次数

标签 统计

java ×2

deserialization ×1

entity ×1

hibernate ×1

jackson ×1

json ×1

ltree ×1

postgresql ×1