GSON java.lang.IllegalArgumentException: class 'xx' declares multiple JSON fields named 'XX' AND StackOverflowError

后端 未结 1 647
不知归路
不知归路 2021-01-25 00:33

I want to convert a sqlResult mapped to a very complex Object to JSON in order to save it to a redis database a value. Now I\'m a getting Error

java.lang.Illegal         


        
相关标签:
1条回答
  • 2021-01-25 00:42

    You didn't post a very detailed question so I hope this will help you a bit:

    A problem you can have is that the field already exists in a Class that you extend. In this case the field would already exist in Class B.

    Say:

    public class A extends B {
        private BigDecimal netAmountTcy;
        private BigDecimal netAmountPcy;   
        private BigDecimal priceTo;  
        private String segment;
    
        private BigDecimal taxAmountTcy;
        private BigDecimal taxAmountPcy;   
        private BigDecimal tradeFeesTcy;
        private BigDecimal tradeFeesPcy;
    
    // getter and setter for the above fields
    
    }
    

    where class B is something like (and maybe more duplicates of course):

    public class B {
        private BigDecimal netAmountPcy;   
    // getter and setter for the above fields
    
    }
    

    Just remove the field "netAmountPcy" Class A and you will still have the field (because it extends the class).

    0 讨论(0)
提交回复
热议问题