XStream
  1. XStream
  2. XSTR-710

Problem on serialize BigDecimal/BigInteger with JsonWriter

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 1.4.4
    • Component/s: Core
    • Labels:
      None
    • JDK version and platform:
      Sun 1.7_09

      Description

      When we use JsonHierarchicalStreamDriver to serialize to json string, Long, Integer,.. shows as a number without ", but when the return type is BigDecimal or BigInteger, it adds ". Example:

      • Long
        {"valor":1}
        
      • BigDecimal
        {"valor":"1"}
        

      To solve it, we are extending JsonWriter and override these functions:

          @Override
          public void startNode(String name, Class clazz) {
          	this.currentClass = clazz;
          	
          	super.startNode(name, clazz);
          }
          
          @Override
          protected void addValue(String value, Type type) {
          	if(currentClass.isAssignableFrom(BigDecimal.class) 
          			|| currentClass.isAssignableFrom(BigInteger.class))
          		type = Type.NUMBER;
          	
          	super.addValue(value, type);
          }
      

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Marcial Atiénzar Navarro
        • Votes:
          0 Vote for this issue
          Watchers:
          2 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: