Json   发布时间:2022-04-22  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了fastjson tostring ref 问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

解决方法serializerFeature.DisableCircularReferenceDetect

JSON.toJSONString(result,serializerFeature.DisableCircularReferenceDetect)
/*
 * Project: DemoJava
 * 
 * File Created at 2017年5月23日
 * 
 * Copyright 2016 CMCC Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * curIoUsby Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license.
 */
package com.curIoUsby.fastjson;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.serializerFeature;

/**
 * @Type FastjsonTest.java
 * @Desc 
 * @author baoyou curIoUsby@163.com
 * @date 2017年5月23日 上午11:01:21
 * @version 
 */
public class FastjsonTest {

     
    
    public static void main(String[] args) {
        FastJsonEntity entity = new FastJsonEntity(1,"baoyou","Hello");
        FastResultEnity result = new FastResultEnity();
        result.setLast(entity);
        List<FastJsonEntity> list = new ArrayList<>();
        list.add(entity);
        result.setHistory(list);
        System.out.println(JSON.toJSONString(result));
        System.out.println(JSON.toJSONString(result,serializerFeature.DisableCircularReferenceDetect));
        
        
    }
}
class FastResultEnity{
    private FastJsonEntity last;
    private List<FastJsonEntity> history;
    public FastJsonEntity getLast() {
        return last;
    }
    public List<FastJsonEntity> getHistory() {
        return history;
    }
    public void setLast(FastJsonEntity last) {
        this.last = last;
    }
    public void setHistory(List<FastJsonEntity> history) {
        this.history = history;
    }
    
}
class FastJsonEntity{
    private int id;
    private String name;
    private String description;
    public int getId() {
        return id;
    }
    public String getName() {
        return name;
    }
    public String getDescription() {
        return description;
    }
    public void setId(int id) {
        this.id = id;
    }
    public void setName(String Name) {
        this.name = name;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public FastJsonEntity(){}
    public FastJsonEntity(int id,String name,String description) {
        this.id = id;
        this.name = name;
        this.description = description;
    }
    
    
}

/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2017年5月23日 baoyou curIoUsby@163.com creat
 */

test

{"history":[{"description":"Hello","id":1,"name":"baoyou"}],"last":{"$ref":"$.history[0]"}}
{"history":[{"description":"Hello","last":{"description":"Hello","name":"baoyou"}}

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

个人主页http://knight-black-bob.iteye.com/


谢谢您的赞助,我会做的更好!

大佬总结

以上是大佬教程为你收集整理的fastjson tostring ref 问题全部内容,希望文章能够帮你解决fastjson tostring ref 问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。