text
stringlengths
30
1.67M
<s> package net . sf . json . sample ; import java . util . HashMap ; import java . util . List ; public class MappedBean extends HashMap { private static final long serialVersionUID = - <NUM_LIT> ; public List getList ( ) { return ( List ) get ( "<STR_LIT:list>" ) ; } public String getName ( ) { return ( String ) get ( "<STR_LIT:name>" ) ; } public void setList ( List list ) { put ( "<STR_LIT:list>" , list ) ; } public void setName ( String name ) { put ( "<STR_LIT:name>" , name ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class PrivateConstructorBean { private int value ; private PrivateConstructorBean ( ) { } public int getValue ( ) { return value ; } public void setValue ( int value ) { this . value = value ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . List ; import java . util . Map ; import net . sf . json . JSONFunction ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class PrimitiveBean { private Object [ ] oarray ; private int [ ] parray ; private ObjectBean pbean ; private boolean pboolean ; private byte pbyte ; private char pchar ; private Class pclass ; private double pdouble ; private String pexcluded ; private float pfloat ; private JSONFunction pfunction ; private int pint ; private List plist ; private long plong ; private Map pmap ; private short pshort ; private String pstring ; public Object [ ] getOarray ( ) { return oarray ; } public int [ ] getParray ( ) { return parray ; } public ObjectBean getPbean ( ) { return pbean ; } public byte getPbyte ( ) { return pbyte ; } public char getPchar ( ) { return pchar ; } public Class getPclass ( ) { return pclass ; } public double getPdouble ( ) { return pdouble ; } public String getPexcluded ( ) { return pexcluded ; } public float getPfloat ( ) { return pfloat ; } public JSONFunction getPfunction ( ) { return pfunction ; } public int getPint ( ) { return pint ; } public List getPlist ( ) { return plist ; } public long getPlong ( ) { return plong ; } public Map getPmap ( ) { return pmap ; } public short getPshort ( ) { return pshort ; } public String getPstring ( ) { return pstring ; } public boolean isPboolean ( ) { return pboolean ; } public void setOarray ( Object [ ] oarray ) { this . oarray = oarray ; } public void setParray ( int [ ] parray ) { this . parray = parray ; } public void setPbean ( ObjectBean pbean ) { this . pbean = pbean ; } public void setPboolean ( boolean pboolean ) { this . pboolean = pboolean ; } public void setPbyte ( byte pbyte ) { this . pbyte = pbyte ; } public void setPchar ( char pchar ) { this . pchar = pchar ; } public void setPclass ( Class pclass ) { this . pclass = pclass ; } public void setPdouble ( double pdouble ) { this . pdouble = pdouble ; } public void setPexcluded ( String pexcluded ) { this . pexcluded = pexcluded ; } public void setPfloat ( float pfloat ) { this . pfloat = pfloat ; } public void setPfunction ( JSONFunction pfunction ) { this . pfunction = pfunction ; } public void setPint ( int pint ) { this . pint = pint ; } public void setPlist ( List plist ) { this . plist = plist ; } public void setPlong ( long plong ) { this . plong = plong ; } public void setPmap ( Map pmap ) { this . pmap = pmap ; } public void setPshort ( short pshort ) { this . pshort = pshort ; } public void setPstring ( String pstring ) { this . pstring = pstring ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import net . sf . json . JSONString ; public class ObjectJSONStringBean implements JSONString { private int id ; private String name ; public int getId ( ) { return id ; } public String getName ( ) { return name ; } public void setId ( int id ) { this . id = id ; } public void setName ( String name ) { this . name = name ; } public String toJSONString ( ) { return new StringBuffer ( ) . append ( "<STR_LIT:{>" ) . append ( "<STR_LIT>" ) . append ( ( name == null ) ? "<STR_LIT>" : name ) . append ( "<STR_LIT>" ) . toString ( ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . HashMap ; import java . util . Map ; public class MappingBean { private Map attributes = new HashMap ( ) ; public void addAttribute ( Object key , Object value ) { this . attributes . put ( key , value ) ; } public Map getAttributes ( ) { return attributes ; } public void setAttributes ( Map attributes ) { this . attributes = attributes ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class BeanA1763699 { private BeanB1763699 [ ] bbeans ; public BeanB1763699 [ ] getBbeans ( ) { return bbeans ; } public void setBbeans ( BeanB1763699 [ ] bbeans ) { this . bbeans = bbeans ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; public class InterfaceBean { private Runnable runnable ; public Runnable getRunnable ( ) { return runnable ; } public void setRunnable ( Runnable runnable ) { this . runnable = runnable ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class Media { private String title ; public String getTitle ( ) { return title ; } public void setTitle ( String title ) { this . title = title ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class MediaBean { private String title ; public String getTitle ( ) { return title ; } public void setTitle ( String title ) { this . title = title ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . ArrayList ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class PlayerList { private ArrayList player ; public ArrayList getPlayer ( ) { return player ; } public void setPlayer ( ArrayList player ) { this . player = player ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . HashMap ; import java . util . Map ; public class JSONTestBean { private String email = "<STR_LIT>" ; private String inventoryID = "<STR_LIT>" ; private String notes = "<STR_LIT>" ; private Map options = new HashMap ( ) ; private String rateID = "<STR_LIT>" ; public String getEmail ( ) { return email ; } public String getInventoryID ( ) { return inventoryID ; } public String getNotes ( ) { return notes ; } public Map getOptions ( ) { return options ; } public String getRateID ( ) { return rateID ; } public void setEmail ( String email ) { this . email = email ; } public void setInventoryID ( String inventoryID ) { this . inventoryID = inventoryID ; } public void setNotes ( String notes ) { this . notes = notes ; } public void setOptions ( Map options ) { this . options = options ; } public void setRateID ( String rateID ) { this . rateID = rateID ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class UnstandardBean { private boolean bool = true ; private int id ; private int integer = <NUM_LIT> ; private String string = "<STR_LIT>" ; public UnstandardBean ( int id ) { this . id = id ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! UnstandardBean . class . isAssignableFrom ( obj . getClass ( ) ) ) { return false ; } return EqualsBuilder . reflectionEquals ( this , obj ) ; } public int getId ( ) { return id ; } public int getInteger ( ) { return integer ; } public String getString ( ) { return string ; } public int hashCode ( ) { return HashCodeBuilder . reflectionHashCode ( this ) ; } public boolean isBool ( ) { return bool ; } public void setBool ( boolean bool ) { this . bool = bool ; } public void setInteger ( int integer ) { this . integer = integer ; } public void setString ( String string ) { this . string = string ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class FieldBean { private int value ; public String string ; public int getValue ( ) { return value ; } public void setValue ( int value ) { this . value = value ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class ArrayBean { private BeanA [ ] beans ; public BeanA [ ] getBeans ( ) { return beans ; } public void setBeans ( BeanA [ ] beans ) { this . beans = beans ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; public class BeanFoo { private String [ ] [ ] items ; public String [ ] [ ] getItems ( ) { return items ; } public void setItems ( String [ ] [ ] items ) { this . items = items ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class NumberArrayBean { private byte [ ] bytes ; private double [ ] doubles ; private float [ ] floats ; private int [ ] ints ; private long [ ] longs ; private short [ ] shorts ; public byte [ ] getBytes ( ) { return bytes ; } public double [ ] getDoubles ( ) { return doubles ; } public float [ ] getFloats ( ) { return floats ; } public int [ ] getInts ( ) { return ints ; } public long [ ] getLongs ( ) { return longs ; } public short [ ] getShorts ( ) { return shorts ; } public void setBytes ( byte [ ] bytes ) { this . bytes = bytes ; } public void setDoubles ( double [ ] doubles ) { this . doubles = doubles ; } public void setFloats ( float [ ] floats ) { this . floats = floats ; } public void setInts ( int [ ] ints ) { this . ints = ints ; } public void setLongs ( long [ ] longs ) { this . longs = longs ; } public void setShorts ( short [ ] shorts ) { this . shorts = shorts ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; public class ChildBean extends ValueBean { private ParentBean parent ; public ParentBean getParent ( ) { return parent ; } public void setParent ( ParentBean parent ) { this . parent = parent ; } } </s>
<s> package net . sf . json . sample ; public class TransientBean extends ValueBean { private transient int transientValue ; public int getTransientValue ( ) { return transientValue ; } public void setTransientValue ( int transientValue ) { this . transientValue = transientValue ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class BeanA { private boolean bool = true ; private int integer = <NUM_LIT> ; private String string = "<STR_LIT>" ; public BeanA ( ) { super ( ) ; } public BeanA ( boolean bool , int integer , String string ) { super ( ) ; this . bool = bool ; this . integer = integer ; this . string = string ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! BeanA . class . isAssignableFrom ( obj . getClass ( ) ) ) { return false ; } return EqualsBuilder . reflectionEquals ( this , obj ) ; } public int getInteger ( ) { return integer ; } public String getString ( ) { return string ; } public int hashCode ( ) { return HashCodeBuilder . reflectionHashCode ( this ) ; } public boolean isBool ( ) { return bool ; } public void setBool ( boolean bool ) { this . bool = bool ; } public void setInteger ( int integer ) { this . integer = integer ; } public void setString ( String string ) { this . string = string ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; public class ClassBean { private Class klass ; public Class getKlass ( ) { return klass ; } public void setKlass ( Class klass ) { this . klass = klass ; } } </s>
<s> package net . sf . json . sample ; public class PropertyBean { private String propertyWithNoReadMethod ; private final String propertyWithNoWriteMethod = "<STR_LIT>" ; public String getPropertyWithNoWriteMethod ( ) { return propertyWithNoWriteMethod ; } public void setPropertyWithNoReadMethod ( String propertyWithNoReadMethod ) { this . propertyWithNoReadMethod = propertyWithNoReadMethod ; } public String valueOfPropertyWithNoReadMethod ( ) { return propertyWithNoReadMethod ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class BeanB extends BeanA { private int [ ] intarray = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } ; public int [ ] getIntarray ( ) { return intarray ; } public void setIntarray ( int [ ] intarray ) { this . intarray = intarray ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . ArrayList ; import java . util . List ; public class ListingBean { private List attributes = new ArrayList ( ) ; public void addAttribute ( Object value ) { this . attributes . add ( value ) ; } public List getAttributes ( ) { return attributes ; } public void setAttributes ( List attributes ) { this . attributes = attributes ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class BeanB1763699 { private String str ; public String getStr ( ) { return str ; } public void setStr ( String str ) { this . str = str ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import net . sf . json . JSONException ; import net . sf . json . util . JsonEventListener ; public class JsonEventAdpater implements JsonEventListener { private int arrayEnd = <NUM_LIT:0> ; private int arrayStart = <NUM_LIT:0> ; private int elementAdded = <NUM_LIT:0> ; private int error = <NUM_LIT:0> ; private int objectEnd = <NUM_LIT:0> ; private int objectStart = <NUM_LIT:0> ; private int propertySet = <NUM_LIT:0> ; private int warning = <NUM_LIT:0> ; public int getArrayEnd ( ) { return arrayEnd ; } public int getArrayStart ( ) { return arrayStart ; } public int getElementAdded ( ) { return elementAdded ; } public int getError ( ) { return error ; } public int getObjectEnd ( ) { return objectEnd ; } public int getObjectStart ( ) { return objectStart ; } public int getPropertySet ( ) { return propertySet ; } public int getWarning ( ) { return warning ; } public void onArrayEnd ( ) { arrayEnd ++ ; } public void onArrayStart ( ) { arrayStart ++ ; } public void onElementAdded ( int index , Object element ) { elementAdded ++ ; } public void onError ( JSONException jsone ) { error ++ ; } public void onObjectEnd ( ) { objectEnd ++ ; } public void onObjectStart ( ) { objectStart ++ ; } public void onPropertySet ( String key , Object value , boolean accumulated ) { propertySet ++ ; } public void onWarning ( String warning ) { this . warning ++ ; } public void reset ( ) { objectStart = <NUM_LIT:0> ; objectEnd = <NUM_LIT:0> ; arrayStart = <NUM_LIT:0> ; arrayEnd = <NUM_LIT:0> ; error = <NUM_LIT:0> ; warning = <NUM_LIT:0> ; propertySet = <NUM_LIT:0> ; elementAdded = <NUM_LIT:0> ; } } </s>
<s> package net . sf . json ; import java . util . List ; import net . sf . ezmorph . test . ArrayAssertions ; import net . sf . json . test . JSONAssert ; public class Assertions extends JSONAssert { public static void assertEquals ( List expecteds , List actuals ) { assertEquals ( null , expecteds , actuals ) ; } public static void assertEquals ( Object expected , Object actual ) { assertEquals ( null , expected , actual ) ; } public static void assertEquals ( String message , List expecteds , List actuals ) { String header = message == null ? "<STR_LIT>" : message + "<STR_LIT::U+0020>" ; if ( expecteds == null ) { fail ( header + "<STR_LIT>" ) ; } if ( actuals == null ) { fail ( header + "<STR_LIT>" ) ; } if ( expecteds == actuals || expecteds . equals ( actuals ) ) { return ; } if ( actuals . size ( ) != expecteds . size ( ) ) { fail ( header + "<STR_LIT>" + expecteds . size ( ) + "<STR_LIT>" + actuals . size ( ) ) ; } int max = expecteds . size ( ) ; for ( int i = <NUM_LIT:0> ; i < max ; i ++ ) { Object o1 = expecteds . get ( i ) ; Object o2 = actuals . get ( i ) ; if ( o1 == null ) { if ( o2 == null ) { return ; } else { fail ( header + "<STR_LIT>" + i + "<STR_LIT>" ) ; } } else { if ( o2 == null ) { fail ( header + "<STR_LIT>" + i + "<STR_LIT>" ) ; } } if ( o1 . getClass ( ) . isArray ( ) && o2 . getClass ( ) . isArray ( ) ) { Object [ ] expected = ( Object [ ] ) o1 ; Object [ ] actual = ( Object [ ] ) o2 ; assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT:;>" , expected , actual ) ; } else if ( List . class . isAssignableFrom ( o1 . getClass ( ) ) && List . class . isAssignableFrom ( o2 . getClass ( ) ) ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( List ) o1 , ( List ) o2 ) ; } else { if ( o1 instanceof String && o2 instanceof JSONFunction ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( String ) o1 , ( JSONFunction ) o2 ) ; } else if ( o1 instanceof JSONFunction && o2 instanceof String ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( JSONFunction ) o1 , ( String ) o2 ) ; } else if ( o1 instanceof JSONObject && o2 instanceof JSONObject ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( JSONObject ) o1 , ( JSONObject ) o2 ) ; } else if ( o1 instanceof JSONArray && o2 instanceof JSONArray ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( JSONArray ) o1 , ( JSONArray ) o2 ) ; } else if ( o1 instanceof JSONFunction && o2 instanceof JSONFunction ) { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , ( JSONFunction ) o1 , ( JSONFunction ) o2 ) ; } else { assertEquals ( header + "<STR_LIT>" + i + "<STR_LIT>" , o1 , o2 ) ; } } } } public static void assertEquals ( String message , Object expected , Object actual ) { if ( expected == null && actual == null ) return ; if ( expected != null && expected . equals ( actual ) ) return ; Class expectedClass = expected . getClass ( ) ; Class actualClass = actual . getClass ( ) ; if ( expectedClass . isArray ( ) && actualClass . isArray ( ) ) { Class expectedInnerType = expectedClass . getComponentType ( ) ; Class actualInnerType = actualClass . getComponentType ( ) ; if ( expectedInnerType . isPrimitive ( ) ) { assertExpectedPrimitiveArrays ( message , expected , actual , expectedInnerType , actualInnerType ) ; } else if ( actualInnerType . isPrimitive ( ) ) { assertActualPrimitiveArrays ( message , expected , actual , expectedInnerType , actualInnerType ) ; } else { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( Object [ ] ) actual ) ; } } else { failNotEquals ( message , expected , actual ) ; } } private static void assertActualPrimitiveArrays ( String message , Object expected , Object actual , Class expectedInnerType , Class actualInnerType ) { if ( Boolean . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Boolean . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( boolean [ ] ) expected , ( boolean [ ] ) actual ) ; } else if ( Boolean . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Boolean [ ] ) expected , ( boolean [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( boolean [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Byte . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Byte . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( byte [ ] ) expected , ( byte [ ] ) actual ) ; } else if ( Byte . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Byte [ ] ) expected , ( byte [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( byte [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Short . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Short . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( short [ ] ) expected , ( short [ ] ) actual ) ; } else if ( Short . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Short [ ] ) expected , ( short [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( short [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Integer . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Integer . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( int [ ] ) expected , ( int [ ] ) actual ) ; } else if ( Integer . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Integer [ ] ) expected , ( int [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( int [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Long . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Long . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( long [ ] ) expected , ( long [ ] ) actual ) ; } else if ( Long . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Long [ ] ) expected , ( long [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( long [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Float . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Float . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( float [ ] ) expected , ( float [ ] ) actual ) ; } else if ( Float . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Float [ ] ) expected , ( float [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( float [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Double . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Double . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( double [ ] ) expected , ( double [ ] ) actual ) ; } else if ( Double . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Double [ ] ) expected , ( double [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( double [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Character . TYPE . isAssignableFrom ( actualInnerType ) ) { if ( Character . TYPE . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( char [ ] ) expected , ( char [ ] ) actual ) ; } else if ( Character . class . isAssignableFrom ( expectedInnerType ) ) { ArrayAssertions . assertEquals ( message , ( Character [ ] ) expected , ( char [ ] ) actual ) ; } else if ( ! expectedInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( Object [ ] ) expected , ( char [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } } private static void assertExpectedPrimitiveArrays ( String message , Object expected , Object actual , Class expectedInnerType , Class actualInnerType ) { if ( Boolean . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Boolean . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( boolean [ ] ) expected , ( boolean [ ] ) actual ) ; } else if ( Boolean . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( boolean [ ] ) expected , ( Boolean [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( boolean [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Byte . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Byte . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( byte [ ] ) expected , ( byte [ ] ) actual ) ; } else if ( Byte . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( byte [ ] ) expected , ( Byte [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( byte [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Short . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Short . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( short [ ] ) expected , ( short [ ] ) actual ) ; } else if ( Short . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( short [ ] ) expected , ( Short [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( short [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Integer . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Integer . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( int [ ] ) expected , ( int [ ] ) actual ) ; } else if ( Integer . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( int [ ] ) expected , ( Integer [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( int [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Long . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Long . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( long [ ] ) expected , ( long [ ] ) actual ) ; } else if ( Long . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( long [ ] ) expected , ( Long [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( long [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Float . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Float . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( float [ ] ) expected , ( float [ ] ) actual ) ; } else if ( Float . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( float [ ] ) expected , ( Float [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( float [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Double . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Double . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( double [ ] ) expected , ( double [ ] ) actual ) ; } else if ( Double . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( double [ ] ) expected , ( Double [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( double [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } else if ( Character . TYPE . isAssignableFrom ( expectedInnerType ) ) { if ( Character . TYPE . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( char [ ] ) expected , ( char [ ] ) actual ) ; } else if ( Character . class . isAssignableFrom ( actualInnerType ) ) { ArrayAssertions . assertEquals ( message , ( char [ ] ) expected , ( Character [ ] ) actual ) ; } else if ( ! actualInnerType . isPrimitive ( ) ) { ArrayAssertions . assertEquals ( message , ( char [ ] ) expected , ( Object [ ] ) actual ) ; } else { failNotEquals ( message , expected , actual ) ; } } } } </s>
<s> package net . sf . json ; import net . sf . json . test . JSONAssert ; import junit . framework . TestCase ; public class TestJSONFunction extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONFunction . class ) ; } public TestJSONFunction ( String name ) { super ( name ) ; } public void testEquals ( ) { JSONFunction expected = new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ; assertFalse ( expected . equals ( null ) ) ; assertFalse ( expected . equals ( new Object ( ) ) ) ; assertFalse ( expected . equals ( "<STR_LIT>" ) ) ; assertFalse ( expected . equals ( new JSONFunction ( "<STR_LIT>" ) ) ) ; assertFalse ( expected . equals ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ) ; assertTrue ( expected . equals ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ) ; } public void testHashCode ( ) { JSONFunction a = new JSONFunction ( new String [ ] { "<STR_LIT>" } , "<STR_LIT>" ) ; JSONFunction b = new JSONFunction ( new String [ ] { "<STR_LIT>" } , "<STR_LIT>" ) ; assertTrue ( a . hashCode ( ) == b . hashCode ( ) ) ; } public void testParse_String ( ) { assertEquals ( "<STR_LIT>" , JSONFunction . parse ( "<STR_LIT>" ) . toString ( ) ) ; } public void testParse_String_withWhiteSpacechars ( ) { assertEquals ( "<STR_LIT>" , JSONFunction . parse ( "<STR_LIT>" ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , JSONFunction . parse ( "<STR_LIT>" ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , JSONFunction . parse ( "<STR_LIT>" ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , JSONFunction . parse ( "<STR_LIT>" ) . toString ( ) ) ; } public void testParse_withSingleArg ( ) { JSONFunction expected = new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ; JSONFunction actual = JSONFunction . parse ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } public void testParse_withMultipleArgs ( ) { JSONFunction expected = new JSONFunction ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , JSONFunction . parse ( "<STR_LIT>" ) ) ; } } </s>
<s> package net . sf . json ; public class TestJSONArrayStaticBuilders_JSONString extends AbstractJSONArrayStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayStaticBuilders_JSONString . class ) ; } public TestJSONArrayStaticBuilders_JSONString ( String name ) { super ( name ) ; } protected Object getSource ( ) { return new JsonBean ( ) ; } public static class JsonBean implements JSONString { public String toJSONString ( ) { return "<STR_LIT>" ; } } } </s>
<s> package net . sf . json ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; public class TestJSONArrayStaticBuilders_Collection_DynaBean extends AbstractJSONArrayStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayStaticBuilders_Collection_DynaBean . class ) ; } public TestJSONArrayStaticBuilders_Collection_DynaBean ( String name ) { super ( name ) ; } protected Object getSource ( ) { Map map = new HashMap ( ) ; String [ ] props = getProperties ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { map . put ( props [ i ] , PropertyConstants . getPropertyClass ( props [ i ] ) ) ; } map . put ( "<STR_LIT:class>" , Class . class ) ; map . put ( "<STR_LIT>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( map ) ; MorphDynaBean dynaBean = null ; try { dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { dynaBean . set ( props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } dynaBean . set ( "<STR_LIT:class>" , Object . class ) ; dynaBean . set ( "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } List list = new ArrayList ( ) ; list . add ( dynaBean ) ; return list ; } } </s>
<s> package net . sf . json ; import java . io . Serializable ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . math . BigDecimal ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Set ; import junit . framework . TestCase ; import net . sf . ezmorph . MorphUtils ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; import net . sf . ezmorph . test . ArrayAssertions ; import net . sf . json . processors . DefaultValueProcessor ; import net . sf . json . processors . DefaultValueProcessorMatcher ; import net . sf . json . processors . PropertyNameProcessor ; import net . sf . json . sample . BeanA ; import net . sf . json . sample . BeanB ; import net . sf . json . sample . BeanC ; import net . sf . json . sample . BeanFoo ; import net . sf . json . sample . BeanWithFunc ; import net . sf . json . sample . ChildBean ; import net . sf . json . sample . ClassBean ; import net . sf . json . sample . EmptyBean ; import net . sf . json . sample . JavaIdentifierBean ; import net . sf . json . sample . ListingBean ; import net . sf . json . sample . MappingBean ; import net . sf . json . sample . NumberBean ; import net . sf . json . sample . ObjectBean ; import net . sf . json . sample . ObjectJSONStringBean ; import net . sf . json . sample . ParentBean ; import net . sf . json . sample . PrimitiveBean ; import net . sf . json . sample . PropertyBean ; import net . sf . json . sample . SetBean ; import net . sf . json . sample . TransientBean ; import net . sf . json . sample . ValueBean ; import net . sf . json . util . CycleDetectionStrategy ; import net . sf . json . util . JSONTokener ; import net . sf . json . util . JSONUtils ; import net . sf . json . util . JavaIdentifierTransformer ; import net . sf . json . util . PropertyExclusionClassMatcher ; import net . sf . json . util . PropertyFilter ; import net . sf . json . util . PropertySetStrategy ; import org . apache . commons . beanutils . PropertyUtils ; public class TestJSONObject extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObject . class ) ; } private JsonConfig jsonConfig ; public TestJSONObject ( String testName ) { super ( testName ) ; } public void testAccumulate ( ) { JSONObject json = new JSONObject ( ) ; json . accumulate ( "<STR_LIT:key>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( <NUM_LIT:1> , json . getInt ( "<STR_LIT:key>" ) ) ; json . accumulate ( "<STR_LIT:key>" , "<STR_LIT:2>" ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , json . getJSONArray ( "<STR_LIT:key>" ) ) ; json . accumulate ( "<STR_LIT:key>" , "<STR_LIT:3>" ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , json . getJSONArray ( "<STR_LIT:key>" ) ) ; } public void testAccumulate__nullObject ( ) { try { new JSONObject ( true ) . accumulate ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_Object__nullJSONObject ( ) { JSONObject jsonObject = JSONObject . fromObject ( ( JSONObject ) null ) ; assertTrue ( jsonObject . isNullObject ( ) ) ; } public void testConstructor_Object_String_Array__nullObject ( ) { jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; JSONObject jsonObject = JSONObject . fromObject ( ( Object ) null , jsonConfig ) ; assertTrue ( jsonObject . isNullObject ( ) ) ; } public void testCycleDetection_beans_noprop ( ) { jsonConfig . setCycleDetectionStrategy ( CycleDetectionStrategy . NOPROP ) ; ParentBean parent = new ParentBean ( ) ; parent . setChild ( new ChildBean ( ) ) ; JSONObject actual = JSONObject . fromObject ( parent , jsonConfig ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT:value>" , <NUM_LIT:0> ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT:value>" , <NUM_LIT:0> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testCycleDetection_beans_null ( ) { jsonConfig . setCycleDetectionStrategy ( CycleDetectionStrategy . LENIENT ) ; ParentBean parent = new ParentBean ( ) ; parent . setChild ( new ChildBean ( ) ) ; JSONObject actual = JSONObject . fromObject ( parent , jsonConfig ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT:value>" , <NUM_LIT:0> ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT:value>" , <NUM_LIT:0> ) . element ( "<STR_LIT>" , new JSONObject ( true ) ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testCycleDetection_beans_strict ( ) { ParentBean parent = new ParentBean ( ) ; parent . setChild ( new ChildBean ( ) ) ; try { JSONObject . fromObject ( parent ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { assertTrue ( expected . getMessage ( ) . endsWith ( "<STR_LIT>" ) ) ; } } public void testDiscard ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:int>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:long>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:boolean>" , "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" , "<STR_LIT:string>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:6> , jsonObject . size ( ) ) ; jsonObject . discard ( "<STR_LIT:int>" ) . discard ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:4> , jsonObject . size ( ) ) ; assertFalse ( jsonObject . has ( "<STR_LIT:int>" ) ) ; assertFalse ( jsonObject . has ( "<STR_LIT>" ) ) ; } public void testElement__duplicateProperty ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; Object o = jsonObject . get ( "<STR_LIT>" ) ; assertFalse ( o instanceof JSONArray ) ; assertEquals ( "<STR_LIT>" , o ) ; } public void testElement__duplicateProperty_2 ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Object o = jsonObject . get ( "<STR_LIT>" ) ; assertTrue ( o instanceof JSONArray ) ; assertEquals ( new JSONArray ( ) . element ( "<STR_LIT>" ) . element ( "<STR_LIT>" ) , o ) ; } public void testElement_Bean ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , new ObjectBean ( ) ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; } public void testElement_Bean_exclusions ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; jsonObject . element ( "<STR_LIT>" , new ObjectBean ( ) , jsonConfig ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_Bean_exclusions_ignoreDefault ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; jsonConfig . setIgnoreDefaultExcludes ( true ) ; jsonObject . element ( "<STR_LIT>" , new ObjectBean ( ) , jsonConfig ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_boolean ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , true ) ; assertTrue ( jsonObject . getBoolean ( "<STR_LIT>" ) ) ; } public void testElement_Boolean ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , Boolean . TRUE ) ; Assertions . assertTrue ( jsonObject . getBoolean ( "<STR_LIT>" ) ) ; } public void testElement_Class ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:class>" , Object . class ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT:class>" ) ) ; } public void testElement_Collection ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:list>" , Collections . EMPTY_LIST ) ; Assertions . assertEquals ( new JSONArray ( ) , jsonObject . getJSONArray ( "<STR_LIT:list>" ) ) ; } public void testElement_Collection2 ( ) { List list = new ArrayList ( ) ; list . add ( new ObjectBean ( ) ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:list>" , list ) ; JSONObject actual = jsonObject . getJSONArray ( "<STR_LIT:list>" ) . getJSONObject ( <NUM_LIT:0> ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; } public void testElement_Collection2_exclusions ( ) { List list = new ArrayList ( ) ; list . add ( new ObjectBean ( ) ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; jsonObject . element ( "<STR_LIT:list>" , list , jsonConfig ) ; JSONObject actual = jsonObject . getJSONArray ( "<STR_LIT:list>" ) . getJSONObject ( <NUM_LIT:0> ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_Collection2_exclusions_ignoreDefault ( ) { List list = new ArrayList ( ) ; list . add ( new ObjectBean ( ) ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; jsonConfig . setIgnoreDefaultExcludes ( true ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:list>" , list , jsonConfig ) ; JSONObject actual = jsonObject . getJSONArray ( "<STR_LIT:list>" ) . getJSONObject ( <NUM_LIT:0> ) ; Assertions . assertTrue ( actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_double ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:double>" , <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , jsonObject . getDouble ( "<STR_LIT:double>" ) , <NUM_LIT> ) ; } public void testElement_int ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:int>" , <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:1> , jsonObject . getInt ( "<STR_LIT:int>" ) ) ; } public void testElement_JSON ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:null>" , JSONNull . getInstance ( ) ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , jsonObject . get ( "<STR_LIT:null>" ) ) ; } public void testElement_JSONFunction ( ) { JSONObject jsonObject = new JSONObject ( ) ; JSONFunction f = new JSONFunction ( "<STR_LIT>" ) ; jsonObject . element ( "<STR_LIT>" , f ) ; Assertions . assertEquals ( f , ( JSONFunction ) jsonObject . get ( "<STR_LIT>" ) ) ; } public void testElement_JSONString ( ) { JSONObject jsonObject = new JSONObject ( ) ; ObjectJSONStringBean bean = new ObjectJSONStringBean ( ) ; bean . setName ( "<STR_LIT>" ) ; jsonObject . element ( "<STR_LIT>" , bean ) ; Assertions . assertEquals ( JSONObject . fromObject ( bean ) , jsonObject . getJSONObject ( "<STR_LIT>" ) ) ; } public void testElement_JSONTokener ( ) { JSONObject jsonObject = new JSONObject ( ) ; JSONTokener tok = new JSONTokener ( "<STR_LIT>" ) ; jsonObject . element ( "<STR_LIT>" , tok ) ; tok . reset ( ) ; Assertions . assertEquals ( JSONObject . fromObject ( tok ) , jsonObject . getJSONObject ( "<STR_LIT>" ) ) ; } public void testElement_long ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:long>" , <NUM_LIT:1L> ) ; assertEquals ( <NUM_LIT:1L> , jsonObject . getLong ( "<STR_LIT:long>" ) ) ; } public void testElement_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , map ) ; Assertions . assertEquals ( JSONObject . fromObject ( map ) , jsonObject . getJSONObject ( "<STR_LIT>" ) ) ; } public void testElement_Map2 ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT:class>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , map ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; } public void testElement_Map2_exclusions ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT:class>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , map , jsonConfig ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_Map2_exclusions_ignoreDefault ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT:class>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; jsonConfig . setIgnoreDefaultExcludes ( true ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , map , jsonConfig ) ; JSONObject actual = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Assertions . assertTrue ( actual . has ( "<STR_LIT:class>" ) ) ; Assertions . assertTrue ( ! actual . has ( "<STR_LIT>" ) ) ; } public void testElement_null_key ( ) { try { new JSONObject ( ) . element ( null , "<STR_LIT:value>" ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testElement_Number ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , new Double ( <NUM_LIT:2> ) ) ; Assertions . assertEquals ( new Double ( <NUM_LIT:2> ) . doubleValue ( ) , jsonObject . getDouble ( "<STR_LIT>" ) , <NUM_LIT> ) ; } public void testElement_Object ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , new BeanA ( ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( new BeanA ( ) ) , jsonObject . getJSONObject ( "<STR_LIT>" ) ) ; } public void testElement_String ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; Assertions . assertEquals ( "<STR_LIT>" , jsonObject . getString ( "<STR_LIT>" ) ) ; } public void testElement_String_JSON ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT:[]>" ) ; Assertions . assertEquals ( new JSONArray ( ) . toString ( ) , jsonObject . getString ( "<STR_LIT>" ) ) ; } public void testElement_String_null ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , ( String ) null ) ; try { jsonObject . getString ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromBean_array ( ) { try { JSONObject . fromObject ( new ArrayList ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } try { JSONObject . fromObject ( new String [ ] { "<STR_LIT>" } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromBean_ClassBean ( ) { ClassBean classBean = new ClassBean ( ) ; classBean . setKlass ( Object . class ) ; JSONObject json = JSONObject . fromObject ( classBean ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; } public void testFromBean_DynaBean ( ) throws Exception { JSONObject json = JSONObject . fromObject ( createDynaBean ( ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:name>" ) ) ; Assertions . assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , json . getJSONObject ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , json . getJSONObject ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( "<STR_LIT>" , ( JSONFunction ) json . get ( "<STR_LIT>" ) ) ; } public void testFromBean_JSONObject ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT:name>" , "<STR_LIT>" ) ; Assertions . assertEquals ( json , JSONObject . fromObject ( json ) ) ; } public void testFromBean_JSONString ( ) { ObjectJSONStringBean bean = new ObjectJSONStringBean ( ) ; bean . setId ( <NUM_LIT:1> ) ; bean . setName ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( bean ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:name>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT:id>" ) ) ; } public void testFromBean_JSONTokener ( ) { JSONTokener jsonTokener = new JSONTokener ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( jsonTokener ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromBean_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT>" , Boolean . TRUE ) ; map . put ( "<STR_LIT>" , new Integer ( <NUM_LIT> ) ) ; map . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( map ) ; assertEquals ( true , json . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromBean_noReadMethod ( ) { JSONObject json = JSONObject . fromObject ( new PropertyBean ( ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; } public void testFromBean_null ( ) { JSONObject json = JSONObject . fromObject ( null ) ; assertTrue ( json . isNullObject ( ) ) ; assertEquals ( JSONNull . getInstance ( ) . toString ( ) , json . toString ( ) ) ; } public void testFromBean_String ( ) { JSONObject json = JSONObject . fromObject ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromBean_use_wrappers ( ) { JSONObject json = JSONObject . fromObject ( Boolean . TRUE ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Byte ( Byte . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Short ( Short . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Integer ( Integer . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Long ( Long . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Float ( Float . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Double ( Double . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Character ( '<CHAR_LIT:A>' ) ) ; assertTrue ( json . isEmpty ( ) ) ; } public void testFromBeanWithJsonPropertyNameProcessor ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerJsonPropertyNameProcessor ( BeanA . class , new PrefixerPropertyNameProcessor ( "<STR_LIT>" ) ) ; JSONObject jsonObject = JSONObject . fromObject ( new BeanA ( ) , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT:3> , jsonObject . names ( ) . size ( ) ) ; assertTrue ( jsonObject . has ( "<STR_LIT>" ) ) ; assertTrue ( jsonObject . has ( "<STR_LIT>" ) ) ; assertTrue ( jsonObject . has ( "<STR_LIT>" ) ) ; } public void testFromDynaBean_full ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT:string>" , String . class ) ; properties . put ( "<STR_LIT:number>" , Integer . class ) ; properties . put ( "<STR_LIT>" , Object [ ] . class ) ; properties . put ( "<STR_LIT:list>" , List . class ) ; properties . put ( "<STR_LIT>" , JSONFunction . class ) ; properties . put ( "<STR_LIT:boolean>" , Boolean . class ) ; properties . put ( "<STR_LIT>" , BeanA . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( "<STR_LIT>" , MorphDynaBean . class , properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT:string>" , "<STR_LIT>" ) ; dynaBean . set ( "<STR_LIT:number>" , new Double ( <NUM_LIT:2> ) ) ; dynaBean . set ( "<STR_LIT>" , new Integer [ ] { new Integer ( <NUM_LIT:1> ) , new Integer ( <NUM_LIT:2> ) } ) ; dynaBean . set ( "<STR_LIT:list>" , new ArrayList ( ) ) ; dynaBean . set ( "<STR_LIT>" , new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; dynaBean . set ( "<STR_LIT:boolean>" , Boolean . TRUE ) ; dynaBean . set ( "<STR_LIT>" , new BeanA ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( dynaBean ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT:string>" ) ) ; assertEquals ( new Double ( <NUM_LIT:2> ) , jsonObject . get ( "<STR_LIT:number>" ) ) ; assertEquals ( Boolean . TRUE , jsonObject . get ( "<STR_LIT:boolean>" ) ) ; Assertions . assertEquals ( "<STR_LIT>" , ( JSONFunction ) jsonObject . get ( "<STR_LIT>" ) ) ; } public void testFromDynaBean_null ( ) { JSONObject jsonObject = JSONObject . fromObject ( null ) ; assertTrue ( jsonObject . isNullObject ( ) ) ; } public void testFromJSONTokener ( ) { JSONTokener jsonTokener = new JSONTokener ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( jsonTokener ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromMap_nested_null_object ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT>" , null ) ; map . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( map ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; Object nested = json . get ( "<STR_LIT>" ) ; assertTrue ( JSONUtils . isNull ( nested ) ) ; } public void testFromMap_null_Map ( ) { JSONObject json = JSONObject . fromObject ( null ) ; assertTrue ( json . isNullObject ( ) ) ; assertEquals ( JSONNull . getInstance ( ) . toString ( ) , json . toString ( ) ) ; } public void testFromObject_array ( ) { try { JSONObject . fromObject ( new ArrayList ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } try { JSONObject . fromObject ( new String [ ] { "<STR_LIT>" } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromObject_Bean ( ) { JSONObject json = JSONObject . fromObject ( new BeanA ( ) ) ; assertEquals ( true , json . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromObject_BeanWithFunc ( ) { JSONObject json = JSONObject . fromObject ( new BeanWithFunc ( "<STR_LIT>" ) ) ; assertNotNull ( json . get ( "<STR_LIT>" ) ) ; assertTrue ( JSONUtils . isFunction ( json . get ( "<STR_LIT>" ) ) ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) . toString ( ) ) ; } public void testFromObject_DynaBean ( ) throws Exception { JSONObject json = JSONObject . fromObject ( createDynaBean ( ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:name>" ) ) ; } public void testFromObject_emptyBean ( ) { EmptyBean bean = new EmptyBean ( ) ; JSONObject json = JSONObject . fromObject ( bean ) ; JSONObject expected = new JSONObject ( ) ; expected . element ( "<STR_LIT>" , new JSONArray ( ) ) ; expected . element ( "<STR_LIT>" , new JSONArray ( ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Double ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , "<STR_LIT>" ) ; expected . element ( "<STR_LIT>" , "<STR_LIT>" ) ; Assertions . assertEquals ( expected , json ) ; } public void testFromObject_ExtendedBean ( ) { JSONObject json = JSONObject . fromObject ( new BeanB ( ) ) ; assertEquals ( true , json . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; assertNotNull ( json . get ( "<STR_LIT>" ) ) ; } public void testFromObject_ignoreTransientFields ( ) { jsonConfig . setIgnoreTransientFields ( true ) ; TransientBean bean = new TransientBean ( ) ; bean . setValue ( <NUM_LIT> ) ; bean . setTransientValue ( <NUM_LIT> ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertTrue ( jsonObject . has ( "<STR_LIT:value>" ) ) ; assertFalse ( jsonObject . has ( "<STR_LIT>" ) ) ; } public void testFromObject_JSONObject ( ) { JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT:id>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:name>" , "<STR_LIT>" ) ; JSONObject actual = JSONObject . fromObject ( expected ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_JSONString ( ) { ObjectJSONStringBean bean = new ObjectJSONStringBean ( ) ; bean . setId ( <NUM_LIT:1> ) ; bean . setName ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( bean ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:name>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT:id>" ) ) ; } public void testFromObject_JSONTokener ( ) { JSONTokener jsonTokener = new JSONTokener ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( jsonTokener ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromObject_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT>" , Boolean . TRUE ) ; map . put ( "<STR_LIT>" , new Integer ( <NUM_LIT> ) ) ; map . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , JSONArray . fromObject ( "<STR_LIT>" ) ) ; map . put ( "<STR_LIT>" , JSONObject . fromObject ( "<STR_LIT>" ) ) ; JSONObject json = JSONObject . fromObject ( map ) ; assertEquals ( true , json . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , json . getJSONArray ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , json . getJSONObject ( "<STR_LIT>" ) ) ; } public void testFromObject_nested_bean ( ) { JSONObject json = JSONObject . fromObject ( new BeanC ( ) ) ; assertNotNull ( json . get ( "<STR_LIT>" ) ) ; assertNotNull ( json . get ( "<STR_LIT>" ) ) ; } public void testFromObject_null ( ) { JSONObject json = JSONObject . fromObject ( null ) ; assertTrue ( json . isNullObject ( ) ) ; assertEquals ( JSONNull . getInstance ( ) . toString ( ) , json . toString ( ) ) ; } public void testFromObject_ObjectBean ( ) { ObjectBean bean = new ObjectBean ( ) ; bean . setPbyte ( Byte . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPshort ( Short . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPint ( Integer . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPlong ( Long . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPfloat ( Float . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPdouble ( Double . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPchar ( new Character ( '<CHAR_LIT:1>' ) ) ; bean . setPboolean ( Boolean . TRUE ) ; bean . setPstring ( "<STR_LIT>" ) ; bean . setParray ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } ) ; bean . setPbean ( new BeanA ( ) ) ; List list = new ArrayList ( ) ; list . add ( "<STR_LIT:1>" ) ; list . add ( "<STR_LIT:2>" ) ; bean . setPlist ( list ) ; Map map = new HashMap ( ) ; map . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; bean . setPmap ( map ) ; bean . setPfunction ( new JSONFunction ( "<STR_LIT>" ) ) ; JSONObject json = JSONObject . fromObject ( bean ) ; assertEquals ( <NUM_LIT:1> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , json . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , json . getDouble ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , json . getDouble ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertTrue ( json . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , json . getJSONArray ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , json . getJSONArray ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:1>" , json . getString ( "<STR_LIT>" ) ) ; JSONObject b = new JSONObject ( ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:true>" ) ; Assertions . assertEquals ( b , json . getJSONObject ( "<STR_LIT>" ) ) ; b = new JSONObject ( ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; Assertions . assertEquals ( b , json . getJSONObject ( "<STR_LIT>" ) ) ; } public void testFromObject_ObjectBean_empty ( ) { ObjectBean bean = new ObjectBean ( ) ; JSONObject json = JSONObject . fromObject ( bean ) ; String [ ] keys = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; for ( int i = <NUM_LIT:0> ; i < keys . length ; i ++ ) { assertTrue ( JSONNull . getInstance ( ) . equals ( json . get ( keys [ i ] ) ) ) ; } } public void testFromObject_String ( ) { JSONObject json = JSONObject . fromObject ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:string>" ) ) ; } public void testFromObject_toBean_DynaBean ( ) { String jsondata = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; JSONObject jsonobj = JSONObject . fromObject ( jsondata ) ; Object bean = JSONObject . toBean ( jsonobj ) ; assertTrue ( bean instanceof MorphDynaBean ) ; JSONObject jsonobj2 = JSONObject . fromObject ( bean ) ; assertNotNull ( jsonobj . getJSONObject ( "<STR_LIT>" ) ) ; assertFalse ( JSONUtils . isNull ( jsonobj . getJSONObject ( "<STR_LIT>" ) ) ) ; assertNotNull ( jsonobj2 . getJSONObject ( "<STR_LIT>" ) ) ; assertFalse ( JSONUtils . isNull ( jsonobj2 . getJSONObject ( "<STR_LIT>" ) ) ) ; JSONObject person1 = jsonobj . getJSONObject ( "<STR_LIT>" ) ; JSONObject person2 = jsonobj2 . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( person1 . get ( "<STR_LIT:name>" ) , person2 . get ( "<STR_LIT:name>" ) ) ; assertEquals ( person1 . get ( "<STR_LIT>" ) . toString ( ) , person2 . get ( "<STR_LIT>" ) . toString ( ) ) ; assertEquals ( person1 . get ( "<STR_LIT:email>" ) . toString ( ) , person2 . get ( "<STR_LIT:email>" ) . toString ( ) ) ; JSONObject address1 = person1 . getJSONObject ( "<STR_LIT:address>" ) ; JSONObject address2 = person2 . getJSONObject ( "<STR_LIT:address>" ) ; assertEquals ( address1 . get ( "<STR_LIT>" ) , address2 . get ( "<STR_LIT>" ) ) ; assertEquals ( address1 . get ( "<STR_LIT>" ) , address2 . get ( "<STR_LIT>" ) ) ; assertEquals ( address1 . get ( "<STR_LIT>" ) , address2 . get ( "<STR_LIT>" ) ) ; } public void testFromObject_use_wrappers ( ) { JSONObject json = JSONObject . fromObject ( Boolean . TRUE ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Byte ( Byte . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Short ( Short . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Integer ( Integer . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Long ( Long . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Float ( Float . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Double ( Double . MIN_VALUE ) ) ; assertTrue ( json . isEmpty ( ) ) ; json = JSONObject . fromObject ( new Character ( '<CHAR_LIT:A>' ) ) ; assertTrue ( json . isEmpty ( ) ) ; } public void testFromObject_withCustomDefaultValueProcessor ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerDefaultValueProcessor ( Integer . class , new NumberDefaultValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( new NumberBean ( ) , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; } public void testFromObject_withCustomDefaultValueProcessor_andMatcher ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerDefaultValueProcessor ( Integer . class , new NumberDefaultValueProcessor ( ) ) ; jsonConfig . setDefaultValueProcessorMatcher ( new NumberDefaultValueProcessorMatcher ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( new NumberBean ( ) , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( NumberDefaultValueProcessor . NUMBER , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT:0> ) , jsonObject . get ( "<STR_LIT>" ) ) ; } public void testFromObject_withExcludesPerClass ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerPropertyExclusion ( BeanA . class , "<STR_LIT>" ) ; JSONObject jsonA = JSONObject . fromObject ( new BeanA ( ) , jsonConfig ) ; JSONObject jsonB = JSONObject . fromObject ( new BeanB ( ) , jsonConfig ) ; assertNotNull ( jsonA ) ; assertNotNull ( jsonB ) ; assertFalse ( jsonA . has ( "<STR_LIT>" ) ) ; assertTrue ( jsonB . has ( "<STR_LIT>" ) ) ; } public void testFromObject_withExcludesPerClassAndMatcher ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerPropertyExclusion ( BeanA . class , "<STR_LIT>" ) ; jsonConfig . setPropertyExclusionClassMatcher ( new BeanAPropertyExclusionClassMatcher ( ) ) ; JSONObject jsonA = JSONObject . fromObject ( new BeanA ( ) , jsonConfig ) ; JSONObject jsonB = JSONObject . fromObject ( new BeanB ( ) , jsonConfig ) ; assertNotNull ( jsonA ) ; assertNotNull ( jsonB ) ; assertFalse ( jsonA . has ( "<STR_LIT>" ) ) ; assertFalse ( jsonB . has ( "<STR_LIT>" ) ) ; } public void testFromObject_withFilters ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJsonPropertyFilter ( new NumberPropertyFilter ( ) ) ; JSONObject json = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( json ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; } public void testFromObject_withFiltersAndExcludes ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJsonPropertyFilter ( new NumberPropertyFilter ( ) ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; JSONObject json = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( json ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; assertTrue ( json . has ( "<STR_LIT>" ) ) ; } public void testFromString_null_String ( ) { JSONObject json = JSONObject . fromObject ( null ) ; assertTrue ( json . isNullObject ( ) ) ; assertEquals ( JSONNull . getInstance ( ) . toString ( ) , json . toString ( ) ) ; } public void testHas ( ) { assertFalse ( new JSONObject ( ) . has ( "<STR_LIT>" ) ) ; assertTrue ( new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT:value>" ) . has ( "<STR_LIT>" ) ) ; } public void testLength ( ) { assertEquals ( <NUM_LIT:0> , new JSONObject ( ) . size ( ) ) ; } public void testLength_nullObject ( ) { assertEquals ( <NUM_LIT:0> , new JSONObject ( true ) . size ( ) ) ; } public void testOptBoolean ( ) { assertFalse ( new JSONObject ( ) . optBoolean ( "<STR_LIT>" ) ) ; } public void testOptBoolean_defaultValue ( ) { assertTrue ( new JSONObject ( ) . optBoolean ( "<STR_LIT>" , true ) ) ; } public void testOptDouble ( ) { assertTrue ( Double . isNaN ( new JSONObject ( ) . optDouble ( "<STR_LIT>" ) ) ) ; } public void testOptDouble_defaultValue ( ) { assertEquals ( <NUM_LIT> , new JSONObject ( ) . optDouble ( "<STR_LIT>" , <NUM_LIT> ) , <NUM_LIT> ) ; } public void testOptInt ( ) { assertEquals ( <NUM_LIT:0> , new JSONObject ( ) . optInt ( "<STR_LIT>" ) ) ; } public void testOptInt_defaultValue ( ) { assertEquals ( <NUM_LIT:1> , new JSONObject ( ) . optInt ( "<STR_LIT>" , <NUM_LIT:1> ) ) ; } public void testOptJSONArray ( ) { JSONObject json = new JSONObject ( ) ; assertNull ( json . optJSONArray ( "<STR_LIT:a>" ) ) ; json . element ( "<STR_LIT:a>" , "<STR_LIT:[]>" ) ; Assertions . assertEquals ( new JSONArray ( ) , json . optJSONArray ( "<STR_LIT:a>" ) ) ; } public void testOptJSONObject ( ) { JSONObject json = new JSONObject ( ) ; assertNull ( json . optJSONObject ( "<STR_LIT:a>" ) ) ; json . element ( "<STR_LIT:a>" , "<STR_LIT:{}>" ) ; Assertions . assertEquals ( new JSONObject ( ) , json . optJSONObject ( "<STR_LIT:a>" ) ) ; } public void testOptLong ( ) { assertEquals ( <NUM_LIT> , new JSONObject ( ) . optLong ( "<STR_LIT>" ) ) ; } public void testOptLong_defaultValue ( ) { assertEquals ( <NUM_LIT:1L> , new JSONObject ( ) . optLong ( "<STR_LIT>" , <NUM_LIT:1L> ) ) ; } public void testOptString ( ) { assertEquals ( "<STR_LIT>" , new JSONObject ( ) . optString ( "<STR_LIT>" ) ) ; } public void testOptString_defaultValue ( ) { assertEquals ( "<STR_LIT>" , new JSONObject ( ) . optString ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testToBean ( ) throws Exception { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; Object bean = JSONObject . toBean ( jsonObject ) ; assertEquals ( jsonObject . get ( "<STR_LIT:name>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:name>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:int>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:int>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:double>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:double>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; List expected = ( List ) JSONArray . toCollection ( jsonObject . getJSONArray ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , ( List ) PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; } public void testToBean_BeanA ( ) { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; BeanA bean = ( BeanA ) JSONObject . toBean ( jsonObject , BeanA . class ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , Boolean . valueOf ( bean . isBool ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , new Integer ( bean . getInteger ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:string>" ) , bean . getString ( ) ) ; } public void testToBean_BeanB ( ) { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; BeanB bean = ( BeanB ) JSONObject . toBean ( jsonObject , BeanB . class ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , Boolean . valueOf ( bean . isBool ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , new Integer ( bean . getInteger ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:string>" ) , bean . getString ( ) ) ; Assertions . assertEquals ( bean . getIntarray ( ) , JSONArray . toArray ( jsonObject . getJSONArray ( "<STR_LIT>" ) ) ) ; } public void testToBean_ClassBean ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , "<STR_LIT>" ) ; ClassBean bean = ( ClassBean ) JSONObject . toBean ( json , ClassBean . class ) ; assertEquals ( Object . class , bean . getKlass ( ) ) ; } public void testToBean_DynaBean__BigInteger_BigDecimal ( ) { BigInteger l = new BigDecimal ( "<STR_LIT>" ) . toBigInteger ( ) ; BigDecimal m = new BigDecimal ( "<STR_LIT>" ) . add ( new BigDecimal ( "<STR_LIT>" ) ) ; JSONObject json = new JSONObject ( ) . element ( "<STR_LIT:i>" , BigInteger . ZERO ) . element ( "<STR_LIT:d>" , MorphUtils . BIGDECIMAL_ONE ) . element ( "<STR_LIT>" , l ) . element ( "<STR_LIT>" , m ) ; Object bean = JSONObject . toBean ( json ) ; Object i = ( ( MorphDynaBean ) bean ) . get ( "<STR_LIT:i>" ) ; Object d = ( ( MorphDynaBean ) bean ) . get ( "<STR_LIT:d>" ) ; assertTrue ( i instanceof Integer ) ; assertTrue ( d instanceof Integer ) ; Object bi = ( ( MorphDynaBean ) bean ) . get ( "<STR_LIT>" ) ; Object bd = ( ( MorphDynaBean ) bean ) . get ( "<STR_LIT>" ) ; assertTrue ( bi instanceof BigInteger ) ; assertTrue ( bd instanceof BigDecimal ) ; } public void testToBean_emptyBean ( ) { EmptyBean bean = new EmptyBean ( ) ; JSONObject json = JSONObject . fromObject ( bean ) ; JSONObject expected = new JSONObject ( ) ; expected . element ( "<STR_LIT>" , new JSONArray ( ) ) ; expected . element ( "<STR_LIT>" , new JSONArray ( ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , new Double ( <NUM_LIT:0> ) ) ; expected . element ( "<STR_LIT>" , "<STR_LIT>" ) ; expected . element ( "<STR_LIT>" , "<STR_LIT>" ) ; Assertions . assertEquals ( expected , json ) ; EmptyBean bean2 = ( EmptyBean ) JSONObject . toBean ( json , EmptyBean . class ) ; ArrayAssertions . assertEquals ( new Object [ <NUM_LIT:0> ] , bean2 . getArrayp ( ) ) ; Assertions . assertEquals ( new ArrayList ( ) , bean2 . getListp ( ) ) ; Assertions . assertEquals ( new Byte ( ( byte ) <NUM_LIT:0> ) , bean2 . getBytep ( ) ) ; Assertions . assertEquals ( new Short ( ( short ) <NUM_LIT:0> ) , bean2 . getShortp ( ) ) ; Assertions . assertEquals ( new Integer ( <NUM_LIT:0> ) , bean2 . getIntp ( ) ) ; Assertions . assertEquals ( new Long ( <NUM_LIT:0> ) , bean2 . getLongp ( ) ) ; Assertions . assertEquals ( new Float ( <NUM_LIT:0> ) , bean2 . getFloatp ( ) ) ; Assertions . assertEquals ( new Double ( <NUM_LIT:0> ) , bean2 . getDoublep ( ) ) ; Assertions . assertEquals ( new Character ( '<STR_LIT>' ) , bean2 . getCharp ( ) ) ; Assertions . assertEquals ( "<STR_LIT>" , bean2 . getStringp ( ) ) ; } public void testToBean_interface ( ) { try { JSONObject . toBean ( JSONObject . fromObject ( "<STR_LIT>" ) , Serializable . class ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testToBean_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; Object obj = JSONObject . toBean ( JSONObject . fromObject ( map ) , Map . class ) ; assertTrue ( obj instanceof Map ) ; assertEquals ( map . get ( "<STR_LIT:name>" ) , ( ( Map ) obj ) . get ( "<STR_LIT:name>" ) ) ; } public void testToBean_nested ( ) throws Exception { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; Object bean = JSONObject . toBean ( jsonObject ) ; assertEquals ( jsonObject . get ( "<STR_LIT:name>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:name>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:int>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:int>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:double>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:double>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; JSONObject nestedJson = jsonObject . getJSONObject ( "<STR_LIT>" ) ; Object nestedBean = PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ; assertEquals ( nestedJson . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( nestedBean , "<STR_LIT>" ) ) ; } public void testToBean_nested_beans__null_object ( ) throws Exception { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; BeanC bean = ( BeanC ) JSONObject . toBean ( jsonObject , BeanC . class ) ; assertNotNull ( bean ) ; BeanA beanA = bean . getBeanA ( ) ; assertNotNull ( beanA ) ; assertEquals ( true , beanA . isBool ( ) ) ; assertEquals ( <NUM_LIT:1> , beanA . getInteger ( ) ) ; assertEquals ( "<STR_LIT>" , beanA . getString ( ) ) ; BeanB beanB = bean . getBeanB ( ) ; assertNull ( beanB ) ; } public void testToBean_nested_beans_in_list__beans ( ) { ListingBean listingBean = new ListingBean ( ) ; ValueBean beanA1 = new ValueBean ( ) ; beanA1 . setValue ( <NUM_LIT> ) ; ValueBean beanA2 = new ValueBean ( ) ; beanA2 . setValue ( <NUM_LIT> ) ; listingBean . addAttribute ( beanA1 ) ; listingBean . addAttribute ( beanA2 ) ; JSONObject jsonObject = JSONObject . fromObject ( listingBean ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , ValueBean . class ) ; ListingBean listingBean2 = ( ListingBean ) JSONObject . toBean ( jsonObject , ListingBean . class , classMap ) ; List attributes = listingBean2 . getAttributes ( ) ; Object ba = attributes . get ( <NUM_LIT:0> ) ; Object bb = attributes . get ( <NUM_LIT:1> ) ; assertTrue ( ba instanceof ValueBean ) ; assertTrue ( bb instanceof ValueBean ) ; assertEquals ( beanA1 . getValue ( ) , ( ( ValueBean ) ba ) . getValue ( ) ) ; assertEquals ( beanA2 . getValue ( ) , ( ( ValueBean ) bb ) . getValue ( ) ) ; } public void testToBean_nested_beans_in_list__DynaBean ( ) { ListingBean listingBean = new ListingBean ( ) ; ValueBean beanA1 = new ValueBean ( ) ; beanA1 . setValue ( <NUM_LIT> ) ; ValueBean beanA2 = new ValueBean ( ) ; beanA2 . setValue ( <NUM_LIT> ) ; listingBean . addAttribute ( beanA1 ) ; listingBean . addAttribute ( beanA2 ) ; JSONObject jsonObject = JSONObject . fromObject ( listingBean ) ; ListingBean listingBean2 = ( ListingBean ) JSONObject . toBean ( jsonObject , ListingBean . class ) ; List attributes = listingBean2 . getAttributes ( ) ; Object ba = attributes . get ( <NUM_LIT:0> ) ; Object bb = attributes . get ( <NUM_LIT:1> ) ; assertTrue ( ba instanceof MorphDynaBean ) ; assertTrue ( bb instanceof MorphDynaBean ) ; assertEquals ( new Integer ( beanA1 . getValue ( ) ) , ( ( MorphDynaBean ) ba ) . get ( "<STR_LIT:value>" ) ) ; assertEquals ( new Integer ( beanA2 . getValue ( ) ) , ( ( MorphDynaBean ) bb ) . get ( "<STR_LIT:value>" ) ) ; } public void testToBean_nested_beans_in_map__beans ( ) { MappingBean mappingBean = new MappingBean ( ) ; ValueBean beanA = new ValueBean ( ) ; beanA . setValue ( <NUM_LIT> ) ; ValueBean beanB = new ValueBean ( ) ; beanB . setValue ( <NUM_LIT> ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanA ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanB ) ; JSONObject jsonObject = JSONObject . fromObject ( mappingBean ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , ValueBean . class ) ; MappingBean mappingBean2 = ( MappingBean ) JSONObject . toBean ( jsonObject , MappingBean . class , classMap ) ; Object ba = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; Object bb = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; assertTrue ( ba instanceof ValueBean ) ; assertTrue ( bb instanceof ValueBean ) ; assertEquals ( beanA . getValue ( ) , ( ( ValueBean ) ba ) . getValue ( ) ) ; assertEquals ( beanB . getValue ( ) , ( ( ValueBean ) bb ) . getValue ( ) ) ; } public void testToBean_nested_beans_in_map__DynaBean ( ) { MappingBean mappingBean = new MappingBean ( ) ; ValueBean beanA = new ValueBean ( ) ; beanA . setValue ( <NUM_LIT> ) ; ValueBean beanB = new ValueBean ( ) ; beanB . setValue ( <NUM_LIT> ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanA ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanB ) ; JSONObject jsonObject = JSONObject . fromObject ( mappingBean ) ; MappingBean mappingBean2 = ( MappingBean ) JSONObject . toBean ( jsonObject , MappingBean . class ) ; Object ba = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; Object bb = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; assertTrue ( ba instanceof MorphDynaBean ) ; assertTrue ( bb instanceof MorphDynaBean ) ; assertEquals ( new Integer ( beanA . getValue ( ) ) , ( ( MorphDynaBean ) ba ) . get ( "<STR_LIT:value>" ) ) ; assertEquals ( new Integer ( beanB . getValue ( ) ) , ( ( MorphDynaBean ) bb ) . get ( "<STR_LIT:value>" ) ) ; } public void testToBean_nested_beans_in_set__beans ( ) { SetBean setBean = new SetBean ( ) ; ValueBean beanA1 = new ValueBean ( ) ; beanA1 . setValue ( <NUM_LIT> ) ; ValueBean beanA2 = new ValueBean ( ) ; beanA2 . setValue ( <NUM_LIT> ) ; setBean . addAttribute ( beanA1 ) ; setBean . addAttribute ( beanA2 ) ; JSONObject jsonObject = JSONObject . fromObject ( setBean ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , ValueBean . class ) ; SetBean setBean2 = ( SetBean ) JSONObject . toBean ( jsonObject , SetBean . class , classMap ) ; assertEquals ( setBean , setBean2 ) ; } public void testToBean_nested_beans_in_set__DynaBean ( ) { SetBean setBean = new SetBean ( ) ; ValueBean beanA1 = new ValueBean ( ) ; beanA1 . setValue ( <NUM_LIT> ) ; ValueBean beanA2 = new ValueBean ( ) ; beanA2 . setValue ( <NUM_LIT> ) ; setBean . addAttribute ( beanA1 ) ; setBean . addAttribute ( beanA2 ) ; JSONObject jsonObject = JSONObject . fromObject ( setBean ) ; } public void testToBean_nested_dynabeans__null_object ( ) throws Exception { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; Object bean = JSONObject . toBean ( jsonObject ) ; assertNotNull ( bean ) ; Object beanA = PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ; assertNotNull ( beanA ) ; assertEquals ( Boolean . TRUE , PropertyUtils . getProperty ( beanA , "<STR_LIT>" ) ) ; assertEquals ( new Integer ( <NUM_LIT:1> ) , PropertyUtils . getProperty ( beanA , "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , PropertyUtils . getProperty ( beanA , "<STR_LIT:string>" ) ) ; Object beanB = PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ; assertNull ( beanB ) ; } public void testtoBean_noWriteMethod ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , "<STR_LIT>" ) ; json . element ( "<STR_LIT>" , "<STR_LIT:value>" ) ; PropertyBean bean = ( PropertyBean ) JSONObject . toBean ( json , PropertyBean . class ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT>" , bean . valueOfPropertyWithNoReadMethod ( ) ) ; assertEquals ( "<STR_LIT>" , bean . getPropertyWithNoWriteMethod ( ) ) ; } public void testToBean_null ( ) { assertNull ( JSONObject . toBean ( null ) ) ; } public void testToBean_null_2 ( ) { assertNull ( JSONObject . toBean ( null , BeanA . class ) ) ; } public void testToBean_null_object ( ) { JSONObject jsonObject = new JSONObject ( true ) ; BeanA bean = ( BeanA ) JSONObject . toBean ( jsonObject , BeanA . class ) ; assertNull ( bean ) ; } public void testToBean_null_values ( ) { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; BeanFoo foo = ( BeanFoo ) JSONObject . toBean ( jsonObject , BeanFoo . class ) ; assertNotNull ( foo ) ; assertNotNull ( foo . getItems ( ) ) ; String [ ] [ ] items = foo . getItems ( ) ; assertEquals ( <NUM_LIT:3> , items . length ) ; assertEquals ( "<STR_LIT>" , items [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" , items [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" , items [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT>" , items [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) ; } public void testToBean_NumberBean ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , new Byte ( ( byte ) <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Short ( ( short ) <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Long ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Float ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Double ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new BigInteger ( "<STR_LIT:2>" ) ) ; json . element ( "<STR_LIT>" , new BigDecimal ( "<STR_LIT:2>" ) ) ; NumberBean bean = ( NumberBean ) JSONObject . toBean ( json , NumberBean . class ) ; assertEquals ( ( byte ) <NUM_LIT:2> , bean . getPbyte ( ) ) ; assertEquals ( ( short ) <NUM_LIT:2> , bean . getPshort ( ) ) ; assertEquals ( <NUM_LIT:2> , bean . getPint ( ) ) ; assertEquals ( <NUM_LIT> , bean . getPlong ( ) ) ; assertEquals ( <NUM_LIT> , bean . getPfloat ( ) , <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , bean . getPdouble ( ) , <NUM_LIT> ) ; assertEquals ( new BigInteger ( "<STR_LIT:2>" ) , bean . getPbigint ( ) ) ; assertEquals ( new BigDecimal ( "<STR_LIT:2>" ) , bean . getPbigdec ( ) ) ; } public void testToBean_NumberBean_2 ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; json . element ( "<STR_LIT>" , new Integer ( <NUM_LIT:2> ) ) ; NumberBean bean = ( NumberBean ) JSONObject . toBean ( json , NumberBean . class ) ; assertEquals ( ( byte ) <NUM_LIT:2> , bean . getPbyte ( ) ) ; assertEquals ( ( short ) <NUM_LIT:2> , bean . getPshort ( ) ) ; assertEquals ( <NUM_LIT:2> , bean . getPint ( ) ) ; assertEquals ( <NUM_LIT> , bean . getPlong ( ) ) ; assertEquals ( <NUM_LIT> , bean . getPfloat ( ) , <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , bean . getPdouble ( ) , <NUM_LIT> ) ; assertEquals ( new BigInteger ( "<STR_LIT:2>" ) , bean . getPbigint ( ) ) ; assertEquals ( new BigDecimal ( "<STR_LIT:2>" ) , bean . getPbigdec ( ) ) ; } public void testToBean_ObjectBean ( ) { ObjectBean bean = new ObjectBean ( ) ; bean . setPbyte ( Byte . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPshort ( Short . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPint ( Integer . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPlong ( Long . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPfloat ( Float . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPdouble ( Double . valueOf ( "<STR_LIT:1>" ) ) ; bean . setPchar ( new Character ( '<CHAR_LIT:1>' ) ) ; bean . setPboolean ( Boolean . TRUE ) ; bean . setPstring ( "<STR_LIT>" ) ; bean . setParray ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } ) ; bean . setPbean ( new BeanA ( ) ) ; List list = new ArrayList ( ) ; list . add ( "<STR_LIT:1>" ) ; list . add ( "<STR_LIT:2>" ) ; bean . setPlist ( list ) ; Map map = new HashMap ( ) ; map . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; bean . setPmap ( map ) ; bean . setPfunction ( new JSONFunction ( "<STR_LIT>" ) ) ; JSONObject json = JSONObject . fromObject ( bean ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , BeanA . class ) ; ObjectBean obj = ( ObjectBean ) JSONObject . toBean ( json , ObjectBean . class , classMap ) ; assertEquals ( Integer . valueOf ( "<STR_LIT:1>" ) , obj . getPbyte ( ) ) ; assertEquals ( Integer . valueOf ( "<STR_LIT:1>" ) , obj . getPshort ( ) ) ; assertEquals ( Integer . valueOf ( "<STR_LIT:1>" ) , obj . getPint ( ) ) ; assertEquals ( Integer . valueOf ( "<STR_LIT:1>" ) , obj . getPlong ( ) ) ; assertEquals ( Double . valueOf ( "<STR_LIT:1>" ) , obj . getPfloat ( ) ) ; assertEquals ( Double . valueOf ( "<STR_LIT:1>" ) , obj . getPdouble ( ) ) ; assertEquals ( "<STR_LIT:1>" , obj . getPchar ( ) ) ; assertEquals ( "<STR_LIT>" , obj . getPstring ( ) ) ; List l = new ArrayList ( ) ; l . add ( "<STR_LIT:a>" ) ; l . add ( "<STR_LIT:b>" ) ; ArrayAssertions . assertEquals ( l . toArray ( ) , ( Object [ ] ) obj . getParray ( ) ) ; l = new ArrayList ( ) ; l . add ( "<STR_LIT:1>" ) ; l . add ( "<STR_LIT:2>" ) ; ArrayAssertions . assertEquals ( l . toArray ( ) , ( Object [ ] ) obj . getPlist ( ) ) ; assertEquals ( new BeanA ( ) , obj . getPbean ( ) ) ; assertTrue ( obj . getPmap ( ) instanceof MorphDynaBean ) ; } public void testToBean_ObjectBean_empty ( ) throws Exception { ObjectBean bean = new ObjectBean ( ) ; JSONObject json = JSONObject . fromObject ( bean ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , BeanA . class ) ; ObjectBean obj = ( ObjectBean ) JSONObject . toBean ( json , ObjectBean . class , classMap ) ; String [ ] keys = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; for ( int i = <NUM_LIT:0> ; i < keys . length ; i ++ ) { assertNull ( PropertyUtils . getProperty ( obj , keys [ i ] ) ) ; } } public void testToBean_rootObject ( ) { JSONObject json = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT:false>" ) . element ( "<STR_LIT>" , <NUM_LIT> ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; BeanA expected = new BeanA ( ) ; BeanA actual = ( BeanA ) JSONObject . toBean ( json , expected , new JsonConfig ( ) ) ; assertNotNull ( actual ) ; assertEquals ( expected , actual ) ; assertFalse ( actual . isBool ( ) ) ; assertEquals ( <NUM_LIT> , actual . getInteger ( ) ) ; assertEquals ( "<STR_LIT>" , actual . getString ( ) ) ; } public void testToBean_withFilters ( ) { BeanA bean = new BeanA ( ) ; bean . setBool ( false ) ; bean . setInteger ( <NUM_LIT> ) ; bean . setString ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( bean ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( BeanA . class ) ; jsonConfig . setJavaPropertyFilter ( new BeanAPropertyFilter ( ) ) ; BeanA actual = ( BeanA ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( actual ) ; assertTrue ( actual . isBool ( ) ) ; assertEquals ( <NUM_LIT> , actual . getInteger ( ) ) ; assertEquals ( "<STR_LIT>" , actual . getString ( ) ) ; } public void testToBean_withNonJavaIdentifier_camelCase_Strategy ( ) { JSONObject json = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonConfig . setJavaIdentifierTransformer ( JavaIdentifierTransformer . CAMEL_CASE ) ; jsonConfig . setRootClass ( JavaIdentifierBean . class ) ; JavaIdentifierBean bean = ( JavaIdentifierBean ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT>" , bean . getCamelCase ( ) ) ; } public void testToBean_withNonJavaIdentifier_underScore_Strategy ( ) { JSONObject json = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonConfig . setJavaIdentifierTransformer ( JavaIdentifierTransformer . UNDERSCORE ) ; jsonConfig . setRootClass ( JavaIdentifierBean . class ) ; JavaIdentifierBean bean = ( JavaIdentifierBean ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT>" , bean . getUnder_score ( ) ) ; } public void testToBean_withNonJavaIdentifier_whitespace_Strategy ( ) { JSONObject json = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonConfig . setJavaIdentifierTransformer ( JavaIdentifierTransformer . WHITESPACE ) ; jsonConfig . setRootClass ( JavaIdentifierBean . class ) ; JavaIdentifierBean bean = ( JavaIdentifierBean ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT>" , bean . getWhitespace ( ) ) ; } public void testToBean_withPropertySetStrategy ( ) { JSONObject json = new JSONObject ( ) . element ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( MappingBean . class ) ; jsonConfig . setPropertySetStrategy ( new MappingPropertySetStrategy ( ) ) ; MappingBean bean = ( MappingBean ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT:value>" , bean . getAttributes ( ) . get ( "<STR_LIT:key>" ) ) ; } public void testToBeanWithJavaPropertyNameProcessor ( ) { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . registerJavaPropertyNameProcessor ( BeanA . class , new SwapPropertyNameProcessor ( ) ) ; jsonConfig . setRootClass ( BeanA . class ) ; BeanA bean = ( BeanA ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertTrue ( bean . isBool ( ) ) ; assertEquals ( "<STR_LIT:false>" , bean . getString ( ) ) ; } public void testToJSONArray ( ) { String json = "<STR_LIT>" ; JSONArray names = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; JSONArray jsonArray = jsonObject . toJSONArray ( names ) ; assertEquals ( "<STR_LIT>" , jsonArray . getString ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , jsonArray . getInt ( <NUM_LIT:1> ) ) ; assertTrue ( jsonArray . getBoolean ( <NUM_LIT:2> ) ) ; } protected void setUp ( ) throws Exception { jsonConfig = new JsonConfig ( ) ; } private MorphDynaBean createDynaBean ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT:name>" , String . class ) ; properties . put ( "<STR_LIT>" , JSONFunction . class ) ; properties . put ( "<STR_LIT>" , JSONString . class ) ; properties . put ( "<STR_LIT>" , JSON . class ) ; properties . put ( "<STR_LIT>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT:name>" , "<STR_LIT>" ) ; dynaBean . set ( "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) ) ; dynaBean . set ( "<STR_LIT>" , new ObjectJSONStringBean ( ) ) ; dynaBean . set ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT:id>" , "<STR_LIT:1>" ) ) ; dynaBean . set ( "<STR_LIT>" , "<STR_LIT>" ) ; return dynaBean ; } public static class BeanAPropertyExclusionClassMatcher extends PropertyExclusionClassMatcher { public Object getMatch ( Class target , Set set ) { for ( Iterator i = set . iterator ( ) ; i . hasNext ( ) ; ) { Class c = ( Class ) i . next ( ) ; if ( BeanA . class . isAssignableFrom ( c ) ) { return c ; } } return null ; } } public static class BeanAPropertyFilter implements PropertyFilter { public boolean apply ( Object source , String name , Object value ) { if ( "<STR_LIT>" . equals ( name ) || "<STR_LIT>" . equals ( name ) ) { return true ; } return false ; } } public static class MappingPropertySetStrategy extends PropertySetStrategy { public void setProperty ( Object bean , String key , Object value ) throws JSONException { ( ( MappingBean ) bean ) . addAttribute ( key , value ) ; } } public static class NumberDefaultValueProcessor implements DefaultValueProcessor { public static final Integer NUMBER = new Integer ( <NUM_LIT> ) ; public Object getDefaultValue ( Class type ) { return NUMBER ; } } public static class NumberDefaultValueProcessorMatcher extends DefaultValueProcessorMatcher { public Object getMatch ( Class target , Set set ) { for ( Iterator i = set . iterator ( ) ; i . hasNext ( ) ; ) { Class c = ( Class ) i . next ( ) ; if ( Number . class . isAssignableFrom ( c ) ) { return c ; } } return null ; } } public static class NumberPropertyFilter implements PropertyFilter { public boolean apply ( Object source , String name , Object value ) { if ( value != null && Number . class . isAssignableFrom ( value . getClass ( ) ) ) { return true ; } return false ; } } public static class SwapPropertyNameProcessor implements PropertyNameProcessor { public String processPropertyName ( Class beanClass , String name ) { if ( name . equals ( "<STR_LIT>" ) ) { return "<STR_LIT:string>" ; } return name ; } } public void test_fromJSONObject ( ) { } public void testCanonicalWrite ( ) throws Exception { JSONArray a = new JSONArray ( ) ; a . add ( true ) ; a . add ( <NUM_LIT:1> ) ; a . add ( <NUM_LIT> ) ; JSONObject o = new JSONObject ( ) ; o . put ( "<STR_LIT:key1>" , "<STR_LIT:1>" ) ; o . put ( "<STR_LIT>" , "<STR_LIT:2>" ) ; o . put ( "<STR_LIT>" , "<STR_LIT:3>" ) ; o . put ( "<STR_LIT:string>" , "<STR_LIT>" ) ; a . add ( o ) ; StringWriter sw = new StringWriter ( ) ; a . writeCanonical ( sw ) ; System . out . println ( sw . toString ( ) ) ; assertEquals ( sw . toString ( ) , "<STR_LIT>" ) ; } } </s>
<s> package net . sf . json ; public class TestJSONArrayStaticBuilders_String extends AbstractJSONArrayStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayStaticBuilders_String . class ) ; } public TestJSONArrayStaticBuilders_String ( String name ) { super ( name ) ; } protected Object getSource ( ) { return "<STR_LIT>" ; } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestCase ; public class TestNotPropertyFilter extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestNotPropertyFilter . class ) ; } public TestNotPropertyFilter ( String testName ) { super ( testName ) ; } public void testApply_true ( ) { NotPropertyFilter filter = new NotPropertyFilter ( new TruePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; } public void testApply_false ( ) { NotPropertyFilter filter = new NotPropertyFilter ( new FalsePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestCase ; public class TestCompositePropertyFilter extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestCompositePropertyFilter . class ) ; } private CompositePropertyFilter filter ; public TestCompositePropertyFilter ( String testName ) { super ( testName ) ; } public void testApply_addFilter ( ) { filter . addPropertyFilter ( new FalsePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; filter . addPropertyFilter ( new TruePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } protected void setUp ( ) throws Exception { filter = new CompositePropertyFilter ( ) ; } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestCase ; import net . sf . json . util . PropertyFilter ; public class TestOrPropertyFilter extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestOrPropertyFilter . class ) ; } public TestOrPropertyFilter ( String testName ) { super ( testName ) ; } public void testApply_false_false ( ) { PropertyFilter filter = new OrPropertyFilter ( new FalsePropertyFilter ( ) , new FalsePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; } public void testApply_false_true ( ) { PropertyFilter filter = new OrPropertyFilter ( new FalsePropertyFilter ( ) , new TruePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } public void testApply_true_false ( ) { PropertyFilter filter = new OrPropertyFilter ( new TruePropertyFilter ( ) , new FalsePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } public void testApply_true_true ( ) { PropertyFilter filter = new OrPropertyFilter ( new TruePropertyFilter ( ) , new TruePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestCase ; public class TestMappingPropertyFilter extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestMappingPropertyFilter . class ) ; } public TestMappingPropertyFilter ( String testName ) { super ( testName ) ; } public void testApply ( ) { MappingPropertyFilter filter = new SampleMappingPropertyFilter ( ) ; filter . addPropertyFilter ( String . class , new TruePropertyFilter ( ) ) ; filter . addPropertyFilter ( Long . class , new TruePropertyFilter ( ) ) ; assertFalse ( filter . apply ( "<STR_LIT:String>" , null , null ) ) ; assertTrue ( filter . apply ( new Long ( <NUM_LIT:1L> ) , null , null ) ) ; } public static class SampleMappingPropertyFilter extends MappingPropertyFilter { protected boolean keyMatches ( Object key , Object source , String name , Object value ) { return ( ( Class ) key ) . isAssignableFrom ( source . getClass ( ) ) && source instanceof Number ; } } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestCase ; import net . sf . json . util . PropertyFilter ; public class TestAndPropertyFilter extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestAndPropertyFilter . class ) ; } public TestAndPropertyFilter ( String testName ) { super ( testName ) ; } public void testApply_false_false ( ) { PropertyFilter filter = new AndPropertyFilter ( new FalsePropertyFilter ( ) , new FalsePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; } public void testApply_false_true ( ) { PropertyFilter filter = new AndPropertyFilter ( new FalsePropertyFilter ( ) , new TruePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; } public void testApply_true_false ( ) { PropertyFilter filter = new AndPropertyFilter ( new TruePropertyFilter ( ) , new FalsePropertyFilter ( ) ) ; assertFalse ( filter . apply ( null , null , null ) ) ; } public void testApply_true_true ( ) { PropertyFilter filter = new AndPropertyFilter ( new TruePropertyFilter ( ) , new TruePropertyFilter ( ) ) ; assertTrue ( filter . apply ( null , null , null ) ) ; } } </s>
<s> package net . sf . json . filters ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestAndPropertyFilter . class ) ) ; suite . addTest ( new TestSuite ( TestCompositePropertyFilter . class ) ) ; suite . addTest ( new TestSuite ( TestNotPropertyFilter . class ) ) ; suite . addTest ( new TestSuite ( TestOrPropertyFilter . class ) ) ; suite . addTest ( new TestSuite ( TestMappingPropertyFilter . class ) ) ; return suite ; } } </s>
<s> package net . sf . json . util ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestJavaIdentifierTransformer . class ) ) ; suite . addTest ( new TestSuite ( TestJSONUtils . class ) ) ; suite . addTest ( new TestSuite ( TestJSONTokener . class ) ) ; suite . addTest ( new TestSuite ( TestJSONBuilder . class ) ) ; suite . addTest ( new TestSuite ( TestJSONStringer . class ) ) ; suite . addTest ( new TestSuite ( TestWebUtils . class ) ) ; return suite ; } } </s>
<s> package net . sf . json . util ; import java . io . StringWriter ; import junit . framework . TestCase ; import net . sf . json . JSONFunction ; import net . sf . json . JSONObject ; public class TestJSONBuilder extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONBuilder . class ) ; } public TestJSONBuilder ( String testName ) { super ( testName ) ; } public void testCreateArray ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . array ( ) . value ( true ) . value ( <NUM_LIT> ) . value ( <NUM_LIT> ) . value ( "<STR_LIT:text>" ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , w . toString ( ) ) ; } public void testCreateEmptyArray ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . array ( ) . endArray ( ) ; assertEquals ( "<STR_LIT:[]>" , w . toString ( ) ) ; } public void testCreateEmptyArrayWithNullObjects ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . array ( ) . value ( null ) . value ( null ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , w . toString ( ) ) ; } public void testCreateEmptyObject ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . object ( ) . endObject ( ) ; assertEquals ( "<STR_LIT:{}>" , w . toString ( ) ) ; } public void testCreateFunctionArray ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . array ( ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , w . toString ( ) ) ; } public void testCreateSimpleObject ( ) { StringWriter w = new StringWriter ( ) ; new JSONBuilder ( w ) . object ( ) . key ( "<STR_LIT>" ) . value ( true ) . key ( "<STR_LIT>" ) . value ( <NUM_LIT> ) . key ( "<STR_LIT>" ) . value ( <NUM_LIT:2> ) . key ( "<STR_LIT:text>" ) . value ( "<STR_LIT:text>" ) . key ( "<STR_LIT>" ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . endObject ( ) ; JSONObject jsonObj = JSONObject . fromObject ( w . toString ( ) ) ; assertEquals ( Boolean . TRUE , jsonObj . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT> ) , jsonObj . get ( "<STR_LIT>" ) ) ; assertEquals ( new Long ( <NUM_LIT:2> ) . longValue ( ) , ( ( Number ) jsonObj . get ( "<STR_LIT>" ) ) . longValue ( ) ) ; assertEquals ( "<STR_LIT:text>" , jsonObj . get ( "<STR_LIT:text>" ) ) ; assertTrue ( JSONUtils . isFunction ( jsonObj . get ( "<STR_LIT>" ) ) ) ; assertEquals ( "<STR_LIT>" , jsonObj . get ( "<STR_LIT>" ) . toString ( ) ) ; } } </s>
<s> package net . sf . json . util ; import junit . framework . TestCase ; import net . sf . json . JSONException ; public class TestJSONTokener extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONTokener . class ) ; } public TestJSONTokener ( String name ) { super ( name ) ; } public void testDehexchar ( ) { assertEquals ( <NUM_LIT:0> , JSONTokener . dehexchar ( '<CHAR_LIT:0>' ) ) ; assertEquals ( <NUM_LIT:1> , JSONTokener . dehexchar ( '<CHAR_LIT:1>' ) ) ; assertEquals ( <NUM_LIT:2> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:3> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:4> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:5> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:6> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:7> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:8> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:9> , JSONTokener . dehexchar ( '<CHAR_LIT:9>' ) ) ; assertEquals ( <NUM_LIT:10> , JSONTokener . dehexchar ( '<CHAR_LIT:a>' ) ) ; assertEquals ( <NUM_LIT:10> , JSONTokener . dehexchar ( '<CHAR_LIT:A>' ) ) ; assertEquals ( <NUM_LIT:11> , JSONTokener . dehexchar ( '<CHAR_LIT:b>' ) ) ; assertEquals ( <NUM_LIT:11> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:12> , JSONTokener . dehexchar ( '<CHAR_LIT:c>' ) ) ; assertEquals ( <NUM_LIT:12> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT> , JSONTokener . dehexchar ( '<CHAR_LIT:e>' ) ) ; assertEquals ( <NUM_LIT> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:15> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; assertEquals ( <NUM_LIT:15> , JSONTokener . dehexchar ( '<CHAR_LIT>' ) ) ; } public void testLength ( ) { assertEquals ( <NUM_LIT:0> , new JSONTokener ( null ) . length ( ) ) ; assertEquals ( <NUM_LIT:0> , new JSONTokener ( "<STR_LIT>" ) . length ( ) ) ; assertEquals ( <NUM_LIT:2> , new JSONTokener ( "<STR_LIT:[]>" ) . length ( ) ) ; } public void testNextChar ( ) { JSONTokener tok = new JSONTokener ( "<STR_LIT:abc>" ) ; assertEquals ( '<CHAR_LIT:a>' , tok . next ( '<CHAR_LIT:a>' ) ) ; try { assertEquals ( '<CHAR_LIT:e>' , tok . next ( '<CHAR_LIT:e>' ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testReset ( ) { JSONTokener tok = new JSONTokener ( "<STR_LIT:abc>" ) ; tok . next ( ) ; tok . next ( ) ; assertEquals ( '<CHAR_LIT:c>' , tok . next ( ) ) ; tok . reset ( ) ; assertEquals ( '<CHAR_LIT:a>' , tok . next ( ) ) ; } } </s>
<s> package net . sf . json . util ; import junit . framework . TestCase ; import net . sf . json . JSONArray ; import net . sf . json . JSONObject ; public class TestWebUtils extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestWebUtils . class ) ; } public TestWebUtils ( String name ) { super ( name ) ; } public void testProtect_comments ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; WebUtils . setWebHijackPreventionStrategy ( WebHijackPreventionStrategy . COMMENTS ) ; String str = WebUtils . protect ( jsonObject ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testProtect_comments_and_shrink ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; WebUtils . setWebHijackPreventionStrategy ( WebHijackPreventionStrategy . COMMENTS ) ; String str = WebUtils . protect ( jsonObject , true ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testProtect_inifiniteLoop ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; WebUtils . setWebHijackPreventionStrategy ( WebHijackPreventionStrategy . INFINITE_LOOP ) ; String str = WebUtils . protect ( jsonObject ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testProtect_inifiniteLoop_and_shrink ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; WebUtils . setWebHijackPreventionStrategy ( WebHijackPreventionStrategy . INFINITE_LOOP ) ; String str = WebUtils . protect ( jsonObject , true ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_array_noquotes ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; JSONArray jsonArray = new JSONArray ( ) . element ( jsonObject ) ; String str = WebUtils . toString ( jsonArray ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_array_withquotes1 ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; JSONArray jsonArray = new JSONArray ( ) . element ( jsonObject ) ; String str = WebUtils . toString ( jsonArray ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_array_withquotes2 ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; JSONArray jsonArray = new JSONArray ( ) . element ( jsonObject ) ; String str = WebUtils . toString ( jsonArray ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_object_noquotes ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; String str = WebUtils . toString ( jsonObject ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_object_withquotes1 ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; String str = WebUtils . toString ( jsonObject ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } public void testToString_object_withquotes2 ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; String str = WebUtils . toString ( jsonObject ) ; assertEquals ( <NUM_LIT:0> , str . compareTo ( "<STR_LIT>" ) ) ; } } </s>
<s> package net . sf . json . util ; import junit . framework . TestCase ; public class TestJavaIdentifierTransformer extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJavaIdentifierTransformer . class ) ; } public TestJavaIdentifierTransformer ( String testName ) { super ( testName ) ; } public void testCamelCase ( ) { JavaIdentifierTransformer jit = JavaIdentifierTransformer . CAMEL_CASE ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; } public void testUnderscore ( ) { JavaIdentifierTransformer jit = JavaIdentifierTransformer . UNDERSCORE ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; } public void testWhitespace ( ) { JavaIdentifierTransformer jit = JavaIdentifierTransformer . WHITESPACE ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , jit . transformToJavaIdentifier ( "<STR_LIT>" ) ) ; } } </s>
<s> package net . sf . json . util ; import junit . framework . TestCase ; import net . sf . json . JSONFunction ; import net . sf . json . JSONObject ; public class TestJSONStringer extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONStringer . class ) ; } public TestJSONStringer ( String testName ) { super ( testName ) ; } public void testCreateArray ( ) { JSONBuilder b = new JSONStringer ( ) . array ( ) . value ( true ) . value ( <NUM_LIT> ) . value ( <NUM_LIT> ) . value ( "<STR_LIT:text>" ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , b . toString ( ) ) ; } public void testCreateEmptyArray ( ) { JSONBuilder b = new JSONStringer ( ) . array ( ) . endArray ( ) ; assertEquals ( "<STR_LIT:[]>" , b . toString ( ) ) ; } public void testCreateEmptyArrayWithNullObjects ( ) { JSONBuilder b = new JSONStringer ( ) . array ( ) . value ( null ) . value ( null ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , b . toString ( ) ) ; } public void testCreateEmptyObject ( ) { JSONBuilder b = new JSONStringer ( ) . object ( ) . endObject ( ) ; assertEquals ( "<STR_LIT:{}>" , b . toString ( ) ) ; } public void testCreateFunctionArray ( ) { JSONBuilder b = new JSONStringer ( ) . array ( ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . endArray ( ) ; assertEquals ( "<STR_LIT>" , b . toString ( ) ) ; } public void testCreateSimpleObject ( ) { JSONBuilder b = new JSONStringer ( ) . object ( ) . key ( "<STR_LIT>" ) . value ( true ) . key ( "<STR_LIT>" ) . value ( <NUM_LIT> ) . key ( "<STR_LIT>" ) . value ( <NUM_LIT:2> ) . key ( "<STR_LIT:text>" ) . value ( "<STR_LIT:text>" ) . key ( "<STR_LIT>" ) . value ( new JSONFunction ( "<STR_LIT>" ) ) . endObject ( ) ; JSONObject jsonObj = JSONObject . fromObject ( b . toString ( ) ) ; assertEquals ( Boolean . TRUE , jsonObj . get ( "<STR_LIT>" ) ) ; assertEquals ( new Double ( <NUM_LIT> ) , jsonObj . get ( "<STR_LIT>" ) ) ; assertEquals ( new Long ( <NUM_LIT:2> ) . longValue ( ) , ( ( Number ) jsonObj . get ( "<STR_LIT>" ) ) . longValue ( ) ) ; assertEquals ( "<STR_LIT:text>" , jsonObj . get ( "<STR_LIT:text>" ) ) ; assertTrue ( JSONUtils . isFunction ( jsonObj . get ( "<STR_LIT>" ) ) ) ; assertEquals ( "<STR_LIT>" , jsonObj . get ( "<STR_LIT>" ) . toString ( ) ) ; } } </s>
<s> package net . sf . json . util ; import java . util . Collections ; import junit . framework . TestCase ; import net . sf . json . JSONArray ; import net . sf . json . JSONException ; import net . sf . json . JSONFunction ; public class TestJSONUtils extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONUtils . class ) ; } public TestJSONUtils ( String name ) { super ( name ) ; } public void testDoubleToString_infinite ( ) { assertEquals ( "<STR_LIT:null>" , JSONUtils . doubleToString ( Double . POSITIVE_INFINITY ) ) ; } public void testDoubleToString_nan ( ) { assertEquals ( "<STR_LIT:null>" , JSONUtils . doubleToString ( Double . NaN ) ) ; } public void testDoubleToString_trailingZeros ( ) { assertEquals ( "<STR_LIT>" , JSONUtils . doubleToString ( <NUM_LIT> ) ) ; } public void testGetFunctionParams ( ) { assertEquals ( "<STR_LIT>" , JSONUtils . getFunctionParams ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:a>" , JSONUtils . getFunctionParams ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , JSONUtils . getFunctionParams ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , JSONUtils . getFunctionParams ( "<STR_LIT>" ) ) ; } public void testIsArray ( ) { assertTrue ( JSONUtils . isArray ( new Object [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new boolean [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new byte [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new char [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new short [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new int [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new long [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new float [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new double [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new Object [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new boolean [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new byte [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new char [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new short [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new int [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new long [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new float [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( new double [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) ; assertTrue ( JSONUtils . isArray ( Collections . EMPTY_SET ) ) ; assertTrue ( JSONUtils . isArray ( Collections . EMPTY_LIST ) ) ; assertTrue ( JSONUtils . isArray ( new JSONArray ( ) ) ) ; } public void testIsFunction ( ) { assertTrue ( JSONUtils . isFunction ( "<STR_LIT>" ) ) ; assertTrue ( JSONUtils . isFunction ( "<STR_LIT>" ) ) ; assertTrue ( JSONUtils . isFunction ( "<STR_LIT>" ) ) ; assertTrue ( JSONUtils . isFunction ( "<STR_LIT>" ) ) ; assertTrue ( JSONUtils . isFunction ( "<STR_LIT>" ) ) ; } public void testNumberToString_null ( ) { try { JSONUtils . numberToString ( null ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testQuote_emptyString ( ) { assertEquals ( "<STR_LIT>" , JSONUtils . quote ( "<STR_LIT>" ) ) ; } public void testQuote_escapeChars ( ) { assertEquals ( "<STR_LIT>" , JSONUtils . quote ( "<STR_LIT>" ) ) ; } public void testQuote_jsonFunction ( ) { JSONFunction jsonFunction = new JSONFunction ( "<STR_LIT:a>" ) ; assertEquals ( "<STR_LIT>" , JSONUtils . quote ( jsonFunction . toString ( ) ) ) ; } public void testQuote_nullString ( ) { assertEquals ( "<STR_LIT>" , JSONUtils . quote ( null ) ) ; } public void testStripQuotes_singleChar_doubleeQuote ( ) { String quoted = "<STR_LIT:\">" ; String actual = JSONUtils . stripQuotes ( quoted ) ; assertEquals ( quoted , actual ) ; } public void testStripQuotes_singleChar_singleQuote ( ) { String quoted = "<STR_LIT:'>" ; String actual = JSONUtils . stripQuotes ( quoted ) ; assertEquals ( quoted , actual ) ; } public void testStripQuotes_twoChars_doubleeQuote ( ) { String quoted = "<STR_LIT>" ; String actual = JSONUtils . stripQuotes ( quoted ) ; assertEquals ( "<STR_LIT>" , actual ) ; } public void testStripQuotes_twoChars_singleQuote ( ) { String quoted = "<STR_LIT>" ; String actual = JSONUtils . stripQuotes ( quoted ) ; assertEquals ( "<STR_LIT>" , actual ) ; } public void testValidity_inifiniteDouble ( ) { try { JSONUtils . testValidity ( new Double ( Double . POSITIVE_INFINITY ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testValidity_inifiniteFloat ( ) { try { JSONUtils . testValidity ( new Float ( Float . POSITIVE_INFINITY ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testValidity_nanDouble ( ) { try { JSONUtils . testValidity ( new Double ( Double . NaN ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testValidity_nanFloat ( ) { try { JSONUtils . testValidity ( new Float ( Float . NaN ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } } </s>
<s> package net . sf . json ; import net . sf . json . util . JSONTokener ; public class TestJSONObjectStaticBuilders_JSONTokener extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_JSONTokener . class ) ; } public TestJSONObjectStaticBuilders_JSONTokener ( String name ) { super ( name ) ; } protected Object getSource ( ) { return new JSONTokener ( "<STR_LIT>" ) ; } } </s>
<s> package net . sf . json ; import junit . framework . TestSuite ; public class JSONTestSuite extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( net . sf . json . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . regexp . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . filters . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . processors . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . util . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . xml . AllTests . suite ( ) ) ; suite . addTest ( net . sf . json . test . AllTests . suite ( ) ) ; return suite ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . json . sample . ArrayJSONStringBean ; import net . sf . json . sample . BeanA ; import net . sf . json . sample . MappingBean ; import net . sf . json . sample . ObjectJSONStringBean ; import net . sf . json . sample . ValueBean ; import net . sf . json . util . JSONTokener ; import org . apache . commons . beanutils . DynaBean ; import org . apache . commons . beanutils . PropertyUtils ; public class TestJSONSerializer extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONSerializer . class ) ; } private JsonConfig jsonConfig ; public TestJSONSerializer ( String name ) { super ( name ) ; } public void testToJava_JSONArray_1 ( ) { setName ( "<STR_LIT>" ) ; JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT:[]>" ) ; Object java = JSONSerializer . toJava ( jsonArray ) ; assertNotNull ( java ) ; assertTrue ( java instanceof List ) ; List list = ( List ) java ; assertEquals ( <NUM_LIT:0> , list . size ( ) ) ; } public void testToJava_JSONArray_2 ( ) { setName ( "<STR_LIT>" ) ; JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT:[]>" ) ; jsonConfig . setArrayMode ( JsonConfig . MODE_OBJECT_ARRAY ) ; Object java = JSONSerializer . toJava ( jsonArray , jsonConfig ) ; assertNotNull ( java ) ; assertTrue ( Object [ ] . class . isAssignableFrom ( java . getClass ( ) ) ) ; Object [ ] array = ( Object [ ] ) java ; assertEquals ( <NUM_LIT:0> , array . length ) ; } public void testToJava_JSONNull_1 ( ) { setName ( "<STR_LIT>" ) ; Object java = JSONSerializer . toJava ( JSONNull . getInstance ( ) ) ; assertNull ( java ) ; } public void testToJava_JSONObject_1 ( ) { setName ( "<STR_LIT>" ) ; Object java = JSONSerializer . toJava ( new JSONObject ( true ) ) ; assertNull ( java ) ; } public void testToJava_JSONObject_2 ( ) throws Exception { setName ( "<STR_LIT>" ) ; String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; Object bean = JSONSerializer . toJava ( jsonObject ) ; assertNotNull ( bean ) ; assertTrue ( bean instanceof DynaBean ) ; assertEquals ( jsonObject . get ( "<STR_LIT:name>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:name>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:int>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:int>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:double>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT:double>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; List expected = ( List ) JSONArray . toCollection ( jsonObject . getJSONArray ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , ( List ) PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ) ; } public void testToJava_JSONObject_3 ( ) throws Exception { setName ( "<STR_LIT>" ) ; String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; jsonConfig . setRootClass ( BeanA . class ) ; Object java = JSONSerializer . toJava ( jsonObject , jsonConfig ) ; assertNotNull ( java ) ; assertTrue ( java instanceof BeanA ) ; BeanA bean = ( BeanA ) java ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , Boolean . valueOf ( bean . isBool ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , new Integer ( bean . getInteger ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:string>" ) , bean . getString ( ) ) ; } public void testToJava_JSONObject_4 ( ) { setName ( "<STR_LIT>" ) ; MappingBean mappingBean = new MappingBean ( ) ; ValueBean beanA = new ValueBean ( ) ; beanA . setValue ( <NUM_LIT> ) ; ValueBean beanB = new ValueBean ( ) ; beanB . setValue ( <NUM_LIT> ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanA ) ; mappingBean . addAttribute ( "<STR_LIT>" , beanB ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , ValueBean . class ) ; JSONObject jsonObject = JSONObject . fromObject ( mappingBean ) ; jsonConfig . setRootClass ( MappingBean . class ) ; jsonConfig . setClassMap ( classMap ) ; Object java = JSONSerializer . toJava ( jsonObject , jsonConfig ) ; assertNotNull ( java ) ; assertTrue ( java instanceof MappingBean ) ; MappingBean mappingBean2 = ( MappingBean ) java ; Object ba = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; Object bb = mappingBean2 . getAttributes ( ) . get ( "<STR_LIT>" ) ; assertTrue ( ba instanceof ValueBean ) ; assertTrue ( bb instanceof ValueBean ) ; assertEquals ( beanA . getValue ( ) , ( ( ValueBean ) ba ) . getValue ( ) ) ; assertEquals ( beanB . getValue ( ) , ( ( ValueBean ) bb ) . getValue ( ) ) ; } public void testToJava_JSONObject_and_reset ( ) throws Exception { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; jsonConfig . setRootClass ( BeanA . class ) ; Object java = JSONSerializer . toJava ( jsonObject , jsonConfig ) ; assertNotNull ( java ) ; assertTrue ( java instanceof BeanA ) ; BeanA bean = ( BeanA ) java ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , Boolean . valueOf ( bean . isBool ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , new Integer ( bean . getInteger ( ) ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:string>" ) , bean . getString ( ) ) ; jsonConfig . reset ( ) ; java = JSONSerializer . toJava ( jsonObject , jsonConfig ) ; assertTrue ( java instanceof DynaBean ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( java , "<STR_LIT>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT>" ) , PropertyUtils . getProperty ( java , "<STR_LIT>" ) ) ; assertEquals ( jsonObject . get ( "<STR_LIT:string>" ) , PropertyUtils . getProperty ( java , "<STR_LIT:string>" ) ) ; } public void testToJSON_JSONString_array ( ) { ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; JSON json = JSONSerializer . toJSON ( bean ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONArray ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , ( JSONArray ) json ) ; } public void testToJSON_JSONString_null ( ) { JSON json = JSONSerializer . toJSON ( ( JSONString ) null ) ; assertNotNull ( json ) ; assertTrue ( JSONNull . getInstance ( ) . equals ( json ) ) ; } public void testToJSON_JSONString_object ( ) { ObjectJSONStringBean bean = new ObjectJSONStringBean ( ) ; bean . setName ( "<STR_LIT>" ) ; JSON json = JSONSerializer . toJSON ( bean ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONObject ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , ( JSONObject ) json ) ; } public void testToJSON_Object_array ( ) { JSON json = JSONSerializer . toJSON ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> } ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONArray ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , ( JSONArray ) json ) ; } public void testToJSON_Object_JSONTokener_array ( ) { JSON json = JSONSerializer . toJSON ( new JSONTokener ( "<STR_LIT>" ) ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONArray ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , ( JSONArray ) json ) ; } public void testToJSON_Object_null ( ) { JSON json = JSONSerializer . toJSON ( ( Object ) null ) ; assertNotNull ( json ) ; assertTrue ( JSONNull . getInstance ( ) . equals ( json ) ) ; } public void testToJSON_Object_object ( ) { JSON json = JSONSerializer . toJSON ( new BeanA ( ) ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONObject ) ; Assertions . assertEquals ( JSONObject . fromObject ( new BeanA ( ) ) , ( JSONObject ) json ) ; } public void testToJSON_String_array ( ) { JSON json = JSONSerializer . toJSON ( "<STR_LIT>" ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONArray ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , ( JSONArray ) json ) ; } public void testToJSON_String_invalid ( ) { try { JSONSerializer . toJSON ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testToJSON_String_null ( ) { JSON json = JSONSerializer . toJSON ( ( String ) null ) ; assertNotNull ( json ) ; assertTrue ( JSONNull . getInstance ( ) . equals ( json ) ) ; } public void testToJSON_String_null_literal ( ) { JSON json = JSONSerializer . toJSON ( "<STR_LIT:null>" ) ; assertNotNull ( json ) ; assertTrue ( JSONNull . getInstance ( ) . equals ( json ) ) ; } public void testToJSON_String_object ( ) { JSON json = JSONSerializer . toJSON ( "<STR_LIT>" ) ; assertNotNull ( json ) ; assertTrue ( json instanceof JSONObject ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , ( JSONObject ) json ) ; } protected void setUp ( ) throws Exception { jsonConfig = new JsonConfig ( ) ; } } </s>
<s> package net . sf . json ; public class TestJSONArrayAsJSON extends AbstractJSONTest { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayAsJSON . class ) ; } public TestJSONArrayAsJSON ( String name ) { super ( name ) ; } protected int getIndent ( ) { return <NUM_LIT:2> ; } protected int getIndentFactor ( ) { return <NUM_LIT:2> ; } protected Object [ ] getIsArrayExpectations ( ) { return new Object [ ] { Boolean . TRUE , new JSONArray ( ) } ; } protected Object [ ] getToStringExpectations1 ( ) { return new Object [ ] { "<STR_LIT>" , JSONArray . fromObject ( "<STR_LIT>" ) } ; } protected Object [ ] getToStringExpectations2 ( ) { return new Object [ ] { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:]>" , JSONArray . fromObject ( "<STR_LIT>" ) } ; } protected Object [ ] getToStringExpectations3 ( ) { return new Object [ ] { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , JSONArray . fromObject ( "<STR_LIT>" ) } ; } protected Object [ ] getWriteExpectations ( ) { return new Object [ ] { "<STR_LIT>" , JSONArray . fromObject ( "<STR_LIT>" ) } ; } } </s>
<s> package net . sf . json . test ; import java . util . HashMap ; import java . util . Map ; import junit . framework . AssertionFailedError ; import junit . framework . TestCase ; import net . sf . json . JSON ; import net . sf . json . JSONArray ; import net . sf . json . JSONFunction ; import net . sf . json . JSONNull ; import net . sf . json . JSONObject ; public class TestJSONAssert extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONAssert . class ) ; } public TestJSONAssert ( String testName ) { super ( testName ) ; } public void testArrayWithNullsShouldFail ( ) { JSONArray one = new JSONArray ( ) ; one . element ( "<STR_LIT:hello>" ) ; one . element ( ( Object ) null ) ; one . element ( "<STR_LIT>" ) ; JSONArray two = new JSONArray ( ) ; two . element ( "<STR_LIT:hello>" ) ; two . element ( ( Object ) null ) ; two . element ( "<STR_LIT>" ) ; try { JSONAssert . assertEquals ( one , two ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { assertTrue ( e . getMessage ( ) . startsWith ( "<STR_LIT>" ) ) ; } } public void testArrayWithNullsShouldPass ( ) { JSONArray one = new JSONArray ( ) ; one . element ( "<STR_LIT:hello>" ) ; one . element ( ( Object ) null ) ; one . element ( "<STR_LIT>" ) ; JSONArray two = new JSONArray ( ) ; two . element ( "<STR_LIT:hello>" ) ; two . element ( ( Object ) null ) ; two . element ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( one , two ) ; } public void testAssertEquals_JSON_JSON__actual_null ( ) { try { JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , null ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__expected_null ( ) { try { JSON actual = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( null , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONArray_JSONArray ( ) { try { JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSON actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONArray_JSONObject ( ) { try { JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSON actual = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONNull_JSONArray ( ) { try { JSON expected = JSONNull . getInstance ( ) ; JSON actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONNull_JSONNull ( ) { try { JSON expected = JSONNull . getInstance ( ) ; JSON actual = JSONNull . getInstance ( ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONObject_JSONArray ( ) { try { JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; JSON actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSON_JSON__JSONObject_JSONObject ( ) { try { JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; JSON actual = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_JSONArray ( ) { Object [ ] values = new Object [ ] { Boolean . valueOf ( true ) , new Integer ( Integer . MAX_VALUE ) , new Long ( Long . MAX_VALUE ) , new Float ( Float . MAX_VALUE ) , new Double ( Double . MAX_VALUE ) , "<STR_LIT>" , new JSONArray ( ) , new JSONObject ( true ) , new JSONObject ( ) , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) , new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> } } ; JSONArray expected = JSONArray . fromObject ( values ) ; JSONArray actual = JSONArray . fromObject ( values ) ; try { JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_JSONArray__actual_null ( ) { try { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , ( JSONArray ) null ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_JSONArray__different_length ( ) { try { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = new JSONArray ( ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_JSONArray__expected_null ( ) { try { JSONArray actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( ( JSONArray ) null , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_JSONArray__nulls ( ) { try { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = new JSONArray ( ) . element ( JSONNull . getInstance ( ) ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } try { JSONArray expected = new JSONArray ( ) . element ( JSONNull . getInstance ( ) ) ; JSONArray actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_String ( ) { try { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONArray_String_fail ( ) { try { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONFunction_String ( ) { try { JSONFunction expected = new JSONFunction ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONFunction_String__actual_null ( ) { try { JSONFunction expected = new JSONFunction ( "<STR_LIT:;>" ) ; JSONAssert . assertEquals ( expected , ( String ) null ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONFunction_String__expected_null ( ) { try { JSONAssert . assertEquals ( ( JSONFunction ) null , "<STR_LIT:;>" ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONFunction_String_fail ( ) { try { JSONFunction expected = new JSONFunction ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONNull_String ( ) { try { JSONNull expected = JSONNull . getInstance ( ) ; String actual = "<STR_LIT:null>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONNull_String__actual_null ( ) { try { JSONNull expected = JSONNull . getInstance ( ) ; JSONAssert . assertEquals ( expected , ( String ) null ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONNull_String__expected_null ( ) { try { JSONAssert . assertEquals ( ( JSONNull ) null , "<STR_LIT:null>" ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject_ ( ) { try { String [ ] names = new String [ ] { "<STR_LIT:b>" , "<STR_LIT:i>" , "<STR_LIT>" , "<STR_LIT:f>" , "<STR_LIT:d>" , "<STR_LIT:s>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; Object [ ] values = new Object [ ] { Boolean . valueOf ( true ) , new Integer ( Integer . MAX_VALUE ) , new Long ( Long . MAX_VALUE ) , new Float ( Float . MAX_VALUE ) , new Double ( Double . MAX_VALUE ) , "<STR_LIT>" , new JSONArray ( ) , new JSONObject ( true ) , new JSONObject ( ) , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) } ; Map map = new HashMap ( ) ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { map . put ( names [ i ] , values [ i ] ) ; } JSONObject expected = JSONObject . fromObject ( map ) ; JSONObject actual = JSONObject . fromObject ( map ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject__actual_null ( ) { try { JSONObject expected = JSONObject . fromObject ( "<STR_LIT:{}>" ) ; JSONAssert . assertEquals ( expected , ( JSONObject ) null ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject__expected_null ( ) { try { JSONObject actual = JSONObject . fromObject ( "<STR_LIT:{}>" ) ; JSONAssert . assertEquals ( ( JSONObject ) null , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject_missingExpectedNamesAreGivenInErrorMessage ( ) { try { JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT:foo>" , "<STR_LIT>" ) ; JSONObject actual = new JSONObject ( ) ; JSONAssert . assertEquals ( expected , actual ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { assertEquals ( "<STR_LIT>" , e . getMessage ( ) ) ; } } public void testAssertEquals_JSONObject_JSONObject_unexpectedNamesAreGivenInErrorMessage ( ) { try { JSONObject expected = new JSONObject ( ) ; JSONObject actual = new JSONObject ( ) . element ( "<STR_LIT:foo>" , "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { assertEquals ( "<STR_LIT>" , e . getMessage ( ) ) ; } } public void testAssertEquals_JSONObject_JSONObject_missingExpectedAnUnexpectedNamesAreBothGivenInErrorMessage ( ) { try { JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT:foo>" , "<STR_LIT>" ) . element ( "<STR_LIT:baz>" , "<STR_LIT>" ) ; JSONObject actual = new JSONObject ( ) . element ( "<STR_LIT:bar>" , "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { assertEquals ( "<STR_LIT>" , e . getMessage ( ) ) ; } } public void testAssertEquals_JSONObject_JSONObject_nullObjects ( ) { try { JSONObject expected = new JSONObject ( true ) ; JSONObject actual = new JSONObject ( true ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject_nullObjects_fail1 ( ) { try { JSONObject expected = new JSONObject ( ) ; JSONObject actual = new JSONObject ( true ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_JSONObject_nullObjects_fail2 ( ) { try { JSONObject expected = new JSONObject ( true ) ; JSONObject actual = new JSONObject ( ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_String ( ) { try { JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_JSONObject_String_fail ( ) { try { JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; String actual = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONArray ( ) { try { String expected = "<STR_LIT>" ; JSONArray actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONArray_fail ( ) { try { String expected = "<STR_LIT>" ; JSONArray actual = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONFunction ( ) { try { String expected = "<STR_LIT>" ; JSONFunction actual = new JSONFunction ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONFunction_fail ( ) { try { JSONFunction actual = new JSONFunction ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONNull ( ) { try { String expected = "<STR_LIT:null>" ; JSONNull actual = JSONNull . getInstance ( ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONObject ( ) { try { String expected = "<STR_LIT>" ; JSONObject actual = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertEquals_String_JSONObject_fail ( ) { try { String expected = "<STR_LIT>" ; JSONObject actual = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONAssert . assertEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertJsonEquals_garbage_json ( ) { try { String expected = "<STR_LIT>" ; String actual = "<STR_LIT:null>" ; JSONAssert . assertJsonEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertJsonEquals_json_garbage ( ) { try { String expected = "<STR_LIT:null>" ; String actual = "<STR_LIT>" ; JSONAssert . assertJsonEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { assertEquals ( e . getMessage ( ) , "<STR_LIT>" ) ; } } public void testAssertJsonEquals_jsonArray_jsonArray ( ) { try { String expected = "<STR_LIT>" ; String actual = "<STR_LIT>" ; JSONAssert . assertJsonEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertJsonEquals_jsonNull_jsonNull ( ) { try { String expected = "<STR_LIT:null>" ; String actual = "<STR_LIT:null>" ; JSONAssert . assertJsonEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertJsonEquals_jsonObject_jsonObject ( ) { try { String expected = "<STR_LIT>" ; String actual = "<STR_LIT>" ; JSONAssert . assertJsonEquals ( expected , actual ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertNotNull_JSONNull ( ) { try { JSONAssert . assertNotNull ( JSONNull . getInstance ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { if ( ! e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { fail ( "<STR_LIT>" ) ; } } } public void testAssertNotNull_jsonObject_null ( ) { try { JSONAssert . assertNotNull ( new JSONObject ( true ) ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { if ( ! e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { fail ( "<STR_LIT>" ) ; } } } public void testAssertNotNull_null ( ) { try { JSONAssert . assertNotNull ( null ) ; fail ( "<STR_LIT>" ) ; } catch ( AssertionFailedError e ) { if ( ! e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { fail ( "<STR_LIT>" ) ; } } } public void testAssertNull_JSONNull ( ) { try { JSONAssert . assertNull ( JSONNull . getInstance ( ) ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertNull_jsonObject_null ( ) { try { JSONAssert . assertNull ( new JSONObject ( true ) ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } public void testAssertNull_null ( ) { try { JSONAssert . assertNull ( null ) ; } catch ( AssertionFailedError e ) { fail ( "<STR_LIT>" ) ; } } } </s>
<s> package net . sf . json . test ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT:test>" ) ; suite . addTest ( new TestSuite ( TestJSONAssert . class ) ) ; return suite ; } } </s>
<s> package net . sf . json ; public class TestJSONObjectStaticBuilders_JSONObject extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_JSONObject . class ) ; } public TestJSONObjectStaticBuilders_JSONObject ( String name ) { super ( name ) ; } protected Object getSource ( ) { String [ ] props = getProperties ( ) ; JSONObject jsonObject = new JSONObject ( ) ; try { for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { jsonObject . element ( props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } jsonObject . element ( "<STR_LIT:class>" , Object . class ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return jsonObject ; } } </s>
<s> package net . sf . json ; import net . sf . json . sample . ObjectBean ; import org . apache . commons . beanutils . PropertyUtils ; public class TestJSONObjectStaticBuilders_ObjectBean extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_ObjectBean . class ) ; } public TestJSONObjectStaticBuilders_ObjectBean ( String name ) { super ( name ) ; } protected Object getSource ( ) { ObjectBean bean = new ObjectBean ( ) ; String [ ] props = getProperties ( ) ; try { for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { PropertyUtils . setProperty ( bean , props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return bean ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; import net . sf . json . sample . BeanA ; import net . sf . json . sample . JsonEventAdpater ; import net . sf . json . sample . PropertyBean ; import org . apache . commons . beanutils . DynaBean ; public class TestJSONObjectEvents extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectEvents . class ) ; } private JsonConfig jsonConfig ; private JsonEventAdpater jsonEventAdpater ; public TestJSONObjectEvents ( String name ) { super ( name ) ; } public void testFromObject_bean ( ) { JSONObject . fromObject ( new BeanA ( ) , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_bean2 ( ) { JSONObject . fromObject ( new PropertyBean ( ) , jsonConfig ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getError ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getWarning ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayEnd ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getObjectStart ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getObjectEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getElementAdded ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getPropertySet ( ) ) ; } public void testFromObject_dynaBean ( ) throws Exception { JSONObject . fromObject ( createDynaBean ( ) , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_error ( ) { try { JSONObject . fromObject ( "<STR_LIT:[]>" , jsonConfig ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getError ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getWarning ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getElementAdded ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getPropertySet ( ) ) ; } } public void testFromObject_JSONObject ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:name>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) ) . element ( "<STR_LIT:int>" , new Integer ( <NUM_LIT:1> ) ) ; JSONObject . fromObject ( jsonObject , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) ) ; map . put ( "<STR_LIT:int>" , new Integer ( <NUM_LIT:1> ) ) ; JSONObject . fromObject ( map , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_string ( ) { JSONObject . fromObject ( "<STR_LIT>" , jsonConfig ) ; assertEvents ( ) ; } protected void setUp ( ) throws Exception { jsonEventAdpater = new JsonEventAdpater ( ) ; jsonConfig = new JsonConfig ( ) ; jsonConfig . addJsonEventListener ( jsonEventAdpater ) ; jsonConfig . enableEventTriggering ( ) ; } protected void tearDown ( ) throws Exception { jsonEventAdpater . reset ( ) ; } private void assertEvents ( ) { assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getError ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getWarning ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayEnd ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getObjectStart ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getObjectEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getElementAdded ( ) ) ; assertEquals ( <NUM_LIT:3> , jsonEventAdpater . getPropertySet ( ) ) ; } private DynaBean createDynaBean ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT:name>" , String . class ) ; properties . put ( "<STR_LIT>" , JSONFunction . class ) ; properties . put ( "<STR_LIT:int>" , Integer . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT:name>" , "<STR_LIT>" ) ; dynaBean . set ( "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) ) ; dynaBean . set ( "<STR_LIT:int>" , new Integer ( <NUM_LIT:1> ) ) ; return dynaBean ; } } </s>
<s> package net . sf . json ; import junit . framework . TestCase ; public abstract class AbstractJSONObjectStaticBuildersTestCase extends TestCase { public AbstractJSONObjectStaticBuildersTestCase ( String testName ) { super ( testName ) ; } public void testFromObject ( ) { JSONObject json = JSONObject . fromObject ( getSource ( ) ) ; assertJSONObject ( json , getProperties ( ) ) ; assertTrue ( ! json . has ( "<STR_LIT:class>" ) ) ; } public void testFromObject_excludes ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setExcludes ( getExclusions ( ) ) ; JSONObject json = JSONObject . fromObject ( getSource ( ) , jsonConfig ) ; assertJSONObject ( json , getProperties ( ) ) ; String [ ] excluded = getExclusions ( ) ; for ( int i = <NUM_LIT:0> ; i < excluded . length ; i ++ ) { assertTrue ( ! json . has ( excluded [ i ] ) ) ; } assertTrue ( ! json . has ( "<STR_LIT:class>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; } public void testFromObject_excludes_ignoreDefaults ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setExcludes ( getExclusions ( ) ) ; jsonConfig . setIgnoreDefaultExcludes ( true ) ; JSONObject json = JSONObject . fromObject ( getSource ( ) , jsonConfig ) ; assertJSONObject ( json , getProperties ( ) ) ; assertTrue ( json . has ( "<STR_LIT:class>" ) ) ; assertTrue ( ! json . has ( "<STR_LIT>" ) ) ; } protected String [ ] getExclusions ( ) { return new String [ ] { "<STR_LIT>" } ; } protected String [ ] getProperties ( ) { return PropertyConstants . getProperties ( ) ; } protected abstract Object getSource ( ) ; private void assertJSONObject ( JSONObject json , String [ ] properties ) { assertNotNull ( json ) ; for ( int i = <NUM_LIT:0> ; i < properties . length ; i ++ ) { assertTrue ( json . has ( properties [ i ] ) ) ; } } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; public class TestJSONObjectAsMap extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectAsMap . class ) ; } private JSONObject jsonObject ; public TestJSONObjectAsMap ( String name ) { super ( name ) ; } public void testClear ( ) { assertEquals ( <NUM_LIT:6> , jsonObject . size ( ) ) ; jsonObject . clear ( ) ; assertEquals ( <NUM_LIT:0> , jsonObject . size ( ) ) ; } public void testContainsKey ( ) { assertTrue ( jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertFalse ( jsonObject . containsKey ( "<STR_LIT>" ) ) ; } public void testContainsValue ( ) { assertTrue ( jsonObject . containsValue ( "<STR_LIT:string>" ) ) ; } public void testIsEmpty ( ) { assertFalse ( jsonObject . isEmpty ( ) ) ; } public void testPut ( ) { String key = "<STR_LIT:key>" ; Object value = "<STR_LIT:value>" ; jsonObject . put ( key , value ) ; assertEquals ( value , jsonObject . get ( key ) ) ; } public void testPutAll ( ) { JSONObject json = new JSONObject ( ) ; Map map = new HashMap ( ) ; map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ; json . putAll ( map ) ; assertEquals ( <NUM_LIT:1> , json . size ( ) ) ; assertEquals ( "<STR_LIT:value>" , json . get ( "<STR_LIT:key>" ) ) ; map . put ( "<STR_LIT:key>" , "<STR_LIT>" ) ; json . putAll ( map ) ; assertEquals ( <NUM_LIT:1> , json . size ( ) ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT:key>" ) ) ; } public void testRemove ( ) { assertTrue ( jsonObject . has ( "<STR_LIT>" ) ) ; jsonObject . remove ( "<STR_LIT>" ) ; assertFalse ( jsonObject . has ( "<STR_LIT>" ) ) ; } protected void setUp ( ) throws Exception { jsonObject = new JSONObject ( ) . element ( "<STR_LIT:int>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:long>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:boolean>" , "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" , "<STR_LIT:string>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
<s> package net . sf . json ; public class TestJSONNullAsJSON extends AbstractJSONTest { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONNullAsJSON . class ) ; } public TestJSONNullAsJSON ( String name ) { super ( name ) ; } protected int getIndent ( ) { return <NUM_LIT:2> ; } protected int getIndentFactor ( ) { return <NUM_LIT:2> ; } protected Object [ ] getIsArrayExpectations ( ) { return new Object [ ] { Boolean . FALSE , JSONNull . getInstance ( ) } ; } protected Object [ ] getToStringExpectations1 ( ) { return new Object [ ] { "<STR_LIT:null>" , JSONNull . getInstance ( ) } ; } protected Object [ ] getToStringExpectations2 ( ) { return new Object [ ] { "<STR_LIT:null>" , JSONNull . getInstance ( ) } ; } protected Object [ ] getToStringExpectations3 ( ) { return new Object [ ] { "<STR_LIT>" , JSONNull . getInstance ( ) } ; } protected Object [ ] getWriteExpectations ( ) { return new Object [ ] { "<STR_LIT:null>" , JSONNull . getInstance ( ) } ; } } </s>
<s> package net . sf . json ; import net . sf . json . sample . PrimitiveBean ; import org . apache . commons . beanutils . PropertyUtils ; public class TestJSONObjectStaticBuilders_PrimitiveBean extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_PrimitiveBean . class ) ; } public TestJSONObjectStaticBuilders_PrimitiveBean ( String name ) { super ( name ) ; } protected Object getSource ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; String [ ] props = getProperties ( ) ; try { for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { PropertyUtils . setProperty ( bean , props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return bean ; } } </s>
<s> package net . sf . json . xml ; import junit . framework . TestCase ; import net . sf . json . Assertions ; import net . sf . json . JSON ; import net . sf . json . JSONArray ; import net . sf . json . JSONNull ; import net . sf . json . JSONObject ; import net . sf . json . test . JSONAssert ; public class TestXMLSerializer_reads extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestXMLSerializer_reads . class ) ; } private XMLSerializer xmlSerializer ; public TestXMLSerializer_reads ( String testName ) { super ( testName ) ; } public void testNullObjectArray ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testNullObjectArray_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testRead_nullObject ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_2 ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_2_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_3 ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_3_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_4 ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_4_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_5 ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testRead_nullObject_5_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , actual ) ; } public void testReadArray_forceTopLevelObject ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setForceTopLevelObject ( true ) ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT:a>" , new JSONArray ( ) . element ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadArray_withText ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONArray ( ) . element ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadBooleanArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadBooleanArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFloatArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFloatArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFunctionObject ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFunctionObject_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFunctionObject_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadFunctionObject_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadIntegerArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadIntegerArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMixedArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMixedArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiBooleanArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiBooleanArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiFloatArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiFloatArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiIntegerArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiIntegerArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiMixedArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiMixedArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiNumberArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiNumberArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiStringArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadMultiStringArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadNestedObject ( ) { String xml = "<STR_LIT>" ; JSONObject actual = ( JSONObject ) xmlSerializer . read ( xml ) ; JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadNumberArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadNumberArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObject_withAttributes ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObject_withAttributes_noTypeHintsEnabled ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsEnabled ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObject_withAttributes_noTypeHintsEnabled_noTypeHintsCompatibility ( ) { String xml = "<STR_LIT>" ; xmlSerializer . setTypeHintsEnabled ( false ) ; xmlSerializer . setTypeHintsCompatibility ( false ) ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObject_withText ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObject_withText_2 ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = new JSONObject ( ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , new JSONArray ( ) . element ( "<STR_LIT>" ) . element ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadObjectFullTypes ( ) { String xml = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; JSONObject actual = ( JSONObject ) xmlSerializer . read ( xml ) ; JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; expected . element ( "<STR_LIT:int>" , new Integer ( <NUM_LIT:1> ) ) ; expected . element ( "<STR_LIT>" , new Double ( <NUM_LIT> ) ) ; expected . element ( "<STR_LIT:number>" , new Double ( <NUM_LIT> ) ) ; expected . element ( "<STR_LIT>" , Boolean . TRUE ) ; expected . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadSimpleObject_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSONObject actual = ( JSONObject ) xmlSerializer . read ( xml ) ; JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadStringArray_withDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadStringArray_withoutDefaultType ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSON expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadWithNamespace_array ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . accumulate ( "<STR_LIT>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testReadWithNamespace_object ( ) { String xml = "<STR_LIT>" ; JSON actual = xmlSerializer . read ( xml ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:1>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testRemoveNameSpacePrefixFromElements ( ) throws Exception { xmlSerializer . setRemoveNamespacePrefixFromElements ( true ) ; JSONObject json = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; assertFalse ( json . getJSONObject ( "<STR_LIT>" ) . has ( "<STR_LIT>" ) ) ; assertTrue ( json . getJSONObject ( "<STR_LIT>" ) . has ( "<STR_LIT>" ) ) ; } public void testSkipNamespaces ( ) throws Exception { xmlSerializer . setSkipNamespaces ( true ) ; JSONObject json = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; assertFalse ( json . getJSONObject ( "<STR_LIT>" ) . has ( "<STR_LIT>" ) ) ; } public void testTrimSpaces ( ) throws Exception { JSONObject json = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; String link = json . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ; assertTrue ( link . startsWith ( "<STR_LIT:U+0020>" ) ) ; assertTrue ( link . endsWith ( "<STR_LIT:U+0020>" ) ) ; xmlSerializer . setTrimSpaces ( true ) ; json = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; link = json . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ; assertFalse ( link . startsWith ( "<STR_LIT:U+0020>" ) ) ; assertFalse ( link . endsWith ( "<STR_LIT:U+0020>" ) ) ; } public void testXmlConversionRules ( ) { String xml = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; xmlSerializer . setForceTopLevelObject ( true ) ; JSONObject actual = ( JSONObject ) xmlSerializer . read ( xml ) ; assertNotNull ( actual ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT:a>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT:url>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , JSONObject . fromObject ( "<STR_LIT>" ) ) . element ( "<STR_LIT>" , JSONObject . fromObject ( "<STR_LIT>" ) ) . accumulate ( "<STR_LIT>" , JSONObject . fromObject ( "<STR_LIT>" ) ) . accumulate ( "<STR_LIT>" , JSONObject . fromObject ( "<STR_LIT>" ) ) ) ) ; JSONAssert . assertEquals ( expected , actual ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; xmlSerializer = new XMLSerializer ( ) ; } } </s>
<s> package net . sf . json . xml ; import junit . framework . TestCase ; import net . sf . json . Assertions ; import net . sf . json . JSON ; import net . sf . json . JSONObject ; import net . sf . json . JSONSerializer ; import net . sf . json . test . JSONAssert ; public class TestUserSubmitted extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestUserSubmitted . class ) ; } public TestUserSubmitted ( String name ) { super ( name ) ; } public void testReadFromXMLToJSON_1735732 ( ) throws Exception { XMLSerializer xmlSerializer = new XMLSerializer ( ) ; JSONObject actual = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT:name>" , "<STR_LIT>" ) ) . accumulate ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT:2>" ) . element ( "<STR_LIT:name>" , "<STR_LIT>" ) ) ; JSONAssert . assertEquals ( expected , actual ) ; } public void testReadFromXMLToJSON_1739066 ( ) throws Exception { XMLSerializer xmlSerializer = new XMLSerializer ( ) ; xmlSerializer . setTrimSpaces ( true ) ; JSONObject actual = ( JSONObject ) xmlSerializer . readFromFile ( "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ) . element ( "<STR_LIT>" , new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; JSONAssert . assertEquals ( expected , actual ) ; } public void testIgnoreWhitespaceWhileReading ( ) { String xml = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; XMLSerializer xmlSerializer = new XMLSerializer ( ) ; xmlSerializer . setSkipWhitespace ( true ) ; JSON json1 = xmlSerializer . read ( xml ) ; xml = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; JSON json2 = xmlSerializer . read ( xml ) ; Assertions . assertEquals ( json2 , json1 ) ; } public void testXMLRoundtrip ( ) { String json = "<STR_LIT>" ; JSONObject json1 = JSONObject . fromObject ( json ) ; XMLSerializer xmlSerializer = new XMLSerializer ( ) ; String xml = xmlSerializer . write ( json1 ) ; JSONObject json2 = ( JSONObject ) xmlSerializer . read ( xml ) ; JSONAssert . assertEquals ( json1 , json2 ) ; assertTrue ( json1 . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( <NUM_LIT:0> ) . get ( "<STR_LIT:id>" ) instanceof Integer ) ; assertTrue ( json2 . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( <NUM_LIT:0> ) . get ( "<STR_LIT:id>" ) instanceof Integer ) ; } public void testXMLWithArraySingleElement ( ) { String testXML = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; JSON expected = JSONSerializer . toJSON ( "<STR_LIT>" ) ; JSONObject actual = convertXML ( testXML ) ; assertNotNull ( actual ) ; Assertions . assertEquals ( expected , actual ) ; } private JSONObject convertXML ( String testXML ) { XMLSerializer xmlSerializer = new XMLSerializer ( ) ; xmlSerializer . setSkipWhitespace ( true ) ; xmlSerializer . setArrayName ( "<STR_LIT>" ) ; xmlSerializer . setForceTopLevelObject ( true ) ; JSON jsonElement = xmlSerializer . read ( testXML ) ; return ( JSONObject ) jsonElement ; } } </s>
<s> package net . sf . json . xml ; import net . sf . json . JSONArray ; import net . sf . json . JSONNull ; import net . sf . json . JSONObject ; import org . custommonkey . xmlunit . XMLTestCase ; public class TestXMLSerializer_writes extends XMLTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestXMLSerializer_writes . class ) ; } private XMLSerializer xmlSerializer ; public TestXMLSerializer_writes ( String testName ) { super ( testName ) ; } public void testWrite_null ( ) throws Exception { String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( null ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteBooleanArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteEmptyObject ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteFunctionArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteFunctionArray_noTypeHintsCompatibility ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; xmlSerializer . setTypeHintsCompatibility ( false ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteJSONArray_collapseProperties ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonObject . accumulate ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonObject . getJSONArray ( "<STR_LIT>" ) . setExpandElements ( true ) ; JSONArray jsonArray = new JSONArray ( ) . element ( jsonObject ) ; String expected = "<STR_LIT>" ; xmlSerializer . setExpandableProperties ( new String [ ] { "<STR_LIT>" } ) ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteJSONNull ( ) throws Exception { String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( JSONNull . getInstance ( ) ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteJSONNull_encoding ( ) throws Exception { String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( JSONNull . getInstance ( ) , "<STR_LIT>" ) ; assertTrue ( xml . startsWith ( expected ) ) ; } public void testWriteJSONObject_collapseProperties ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonObject . accumulate ( "<STR_LIT>" , "<STR_LIT>" ) ; jsonObject . getJSONArray ( "<STR_LIT>" ) . setExpandElements ( true ) ; String expected = "<STR_LIT>" ; xmlSerializer . setExpandableProperties ( new String [ ] { "<STR_LIT>" } ) ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteMultiBooleanArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteMultiNumberArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteMultiStringArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNestedNullObject ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNullObject ( ) throws Exception { JSONObject jsonObject = new JSONObject ( true ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNullObject_noTypeHintsCompatibility ( ) throws Exception { JSONObject jsonObject = new JSONObject ( true ) ; String expected = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNullObjectArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNullObjectArray_noTypeHintsCompatibility ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; xmlSerializer . setTypeHintsCompatibility ( false ) ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteNumberArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_full_types ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_withAttributes ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_withNamespacePrefix ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; xmlSerializer . setNamespaceLenient ( true ) ; String xml = xmlSerializer . write ( jsonObject ) ; assertTrue ( xml . trim ( ) . endsWith ( expected ) ) ; } public void testWriteObject_withNamespaces ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" + "<STR_LIT>" ; xmlSerializer . setNamespace ( null , "<STR_LIT>" ) ; xmlSerializer . addNamespace ( "<STR_LIT>" , "<STR_LIT>" ) ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_withNamespaces_element ( ) throws Exception { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" + "<STR_LIT>" ; xmlSerializer . setNamespace ( null , "<STR_LIT>" , "<STR_LIT>" ) ; xmlSerializer . addNamespace ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_withText ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObject_withText_2 ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteObjectArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteStringArray ( ) throws Exception { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; String expected = "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonArray ) ; assertXMLEqual ( expected , xml ) ; } public void testWriteWithNamespace ( ) throws Exception { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT:1>" ) ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String xml = xmlSerializer . write ( jsonObject ) ; assertXMLEqual ( expected , xml ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; xmlSerializer = new XMLSerializer ( ) ; } } </s>
<s> package net . sf . json . xml ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestXMLSerializer_reads . class ) ) ; suite . addTest ( new TestSuite ( TestXMLSerializer_writes . class ) ) ; suite . addTest ( new TestSuite ( TestUserSubmitted . class ) ) ; return suite ; } } </s>
<s> package net . sf . json ; import java . io . StringWriter ; import java . io . IOException ; import java . math . BigDecimal ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . ezmorph . MorphUtils ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; import net . sf . json . sample . ArrayJSONStringBean ; import net . sf . json . sample . BeanA ; import net . sf . json . util . JSONTokener ; import org . apache . commons . beanutils . DynaBean ; public class TestJSONArray extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArray . class ) ; } public TestJSONArray ( String testName ) { super ( testName ) ; } public void testDiscard ( ) { JSONArray jsonArray = new JSONArray ( ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" ) . element ( "<STR_LIT>" ) . element ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . discard ( "<STR_LIT:string>" ) . discard ( <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:3> , jsonArray . size ( ) ) ; assertFalse ( jsonArray . contains ( "<STR_LIT:string>" ) ) ; assertFalse ( jsonArray . contains ( "<STR_LIT:1>" ) ) ; } public void testConstructor_Collection ( ) { List l = new ArrayList ( ) ; l . add ( Boolean . TRUE ) ; l . add ( new Integer ( <NUM_LIT:1> ) ) ; l . add ( "<STR_LIT:string>" ) ; l . add ( Object . class ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_Collection_JSONArray ( ) { List l = new ArrayList ( ) ; l . add ( JSONArray . fromObject ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> } ) ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_Collection_JSONFunction ( ) { List l = new ArrayList ( ) ; l . add ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_Collection_JSONString ( ) { ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; List l = new ArrayList ( ) ; l . add ( bean ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_Collection_nulls ( ) { List l = new ArrayList ( ) ; l . add ( null ) ; l . add ( null ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_func ( ) { JSONArray expected = JSONArray . fromObject ( new String [ ] { "<STR_LIT:'>" + new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) . toString ( ) + "<STR_LIT:'>" } ) ; JSONArray actual = JSONArray . fromObject ( new String [ ] { "<STR_LIT>" } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_func2 ( ) { JSONArray expected = JSONArray . fromObject ( new String [ ] { "<STR_LIT:\">" + new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) . toString ( ) + "<STR_LIT:\">" } ) ; JSONArray actual = JSONArray . fromObject ( new String [ ] { "<STR_LIT>" } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_JSONArray ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_JSONTokener_functions ( ) { testJSONArray ( new JSONTokener ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testConstructor_JSONTokener_nulls ( ) { testJSONArray ( new JSONTokener ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testConstructor_JSONTokener_syntax_errors ( ) { try { JSONArray . fromObject ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_Object_Array ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { "<STR_LIT>" , new Integer ( <NUM_LIT:1> ) } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_Array ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> } } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_BigDecimal ( ) { Number [ ] numberArray = new Number [ ] { BigDecimal . valueOf ( <NUM_LIT> , <NUM_LIT:10> ) , new BigDecimal ( "<STR_LIT>" ) , new BigDecimal ( "<STR_LIT>" ) } ; assertEquals ( "<STR_LIT>" , numberArray [ <NUM_LIT:0> ] . toString ( ) ) ; assertEquals ( "<STR_LIT>" , numberArray [ <NUM_LIT:1> ] . toString ( ) ) ; assertEquals ( "<STR_LIT>" , numberArray [ <NUM_LIT:2> ] . toString ( ) ) ; JSONArray jsonNumArray = JSONArray . fromObject ( numberArray ) ; assertEquals ( "<STR_LIT>" , jsonNumArray . get ( <NUM_LIT:0> ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , jsonNumArray . get ( <NUM_LIT:1> ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , jsonNumArray . get ( <NUM_LIT:2> ) . toString ( ) ) ; } public void testConstructor_Object_Array_BigInteger ( ) { Number [ ] numberArray = new Number [ ] { new BigInteger ( "<STR_LIT>" ) , new BigInteger ( "<STR_LIT>" ) } ; assertEquals ( "<STR_LIT>" , numberArray [ <NUM_LIT:0> ] . toString ( ) ) ; assertEquals ( "<STR_LIT>" , numberArray [ <NUM_LIT:1> ] . toString ( ) ) ; JSONArray jsonNumArray = JSONArray . fromObject ( numberArray ) ; assertEquals ( "<STR_LIT>" , jsonNumArray . get ( <NUM_LIT:0> ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , jsonNumArray . get ( <NUM_LIT:1> ) . toString ( ) ) ; } public void testConstructor_Object_Array_Class ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { Object . class } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_functions ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new JSONFunction [ ] { new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_functions_2 ( ) { JSONArray expected = JSONArray . fromObject ( new JSONFunction [ ] { new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) } ) ; JSONArray actual = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_functions_3 ( ) { JSONArray expected = JSONArray . fromObject ( new JSONFunction [ ] { new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) } ) ; JSONArray actual = JSONArray . fromObject ( new String [ ] { "<STR_LIT>" } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_JSONArray ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { JSONArray . fromObject ( "<STR_LIT>" ) } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_JSONString ( ) { ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { bean } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_Object_Array_nulls ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Object [ ] { null , null } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testConstructor_primitive_array_boolean ( ) { testJSONArray ( new boolean [ ] { true , false } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_byte ( ) { testJSONArray ( new byte [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_char ( ) { testJSONArray ( new char [ ] { '<CHAR_LIT:a>' , '<CHAR_LIT:b>' , '<CHAR_LIT:c>' } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_double ( ) { testJSONArray ( new double [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_double_Infinity ( ) { try { JSONArray . fromObject ( new double [ ] { Double . NEGATIVE_INFINITY } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } try { JSONArray . fromObject ( new double [ ] { Double . POSITIVE_INFINITY } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_primitive_array_double_NaNs ( ) { try { JSONArray . fromObject ( new double [ ] { Double . NaN } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_primitive_array_float ( ) { testJSONArray ( new float [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_float_Infinity ( ) { try { JSONArray . fromObject ( new float [ ] { Float . NEGATIVE_INFINITY } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } try { JSONArray . fromObject ( new float [ ] { Float . POSITIVE_INFINITY } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_primitive_array_float_NaNs ( ) { try { JSONArray . fromObject ( new float [ ] { Float . NaN } ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_primitive_array_int ( ) { testJSONArray ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_long ( ) { testJSONArray ( new long [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , "<STR_LIT>" ) ; } public void testConstructor_primitive_array_short ( ) { testJSONArray ( new short [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , "<STR_LIT>" ) ; } public void testConstructor_String_functions ( ) { testJSONArray ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testConstructor_String_functions_multi ( ) { testJSONArray ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testCycleDetection_arrays ( ) { Object [ ] array1 = new Object [ <NUM_LIT:2> ] ; Object [ ] array2 = new Object [ <NUM_LIT:2> ] ; array1 [ <NUM_LIT:0> ] = new Integer ( <NUM_LIT:1> ) ; array1 [ <NUM_LIT:1> ] = array2 ; array2 [ <NUM_LIT:0> ] = new Integer ( <NUM_LIT:2> ) ; array2 [ <NUM_LIT:1> ] = array1 ; try { JSONArray . fromObject ( array1 ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { assertTrue ( expected . getMessage ( ) . endsWith ( "<STR_LIT>" ) ) ; } } public void testElement_Array ( ) { JSONArray array = new JSONArray ( ) ; int [ ] ints = { <NUM_LIT:1> , <NUM_LIT:2> } ; array . element ( ints ) ; Assertions . assertEquals ( JSONArray . fromObject ( ints ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_boolean ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( true ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertTrue ( jsonArray . getBoolean ( <NUM_LIT:0> ) ) ; } public void testElement_Boolean ( ) { JSONArray array = new JSONArray ( ) ; array . element ( Boolean . TRUE ) ; Assertions . assertTrue ( array . getBoolean ( <NUM_LIT:0> ) ) ; } public void testElement_Collection ( ) { List l = new ArrayList ( ) ; l . add ( Boolean . TRUE ) ; l . add ( new Integer ( <NUM_LIT:1> ) ) ; l . add ( "<STR_LIT:string>" ) ; JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( l ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , jsonArray . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_double ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT> ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertEquals ( <NUM_LIT> , jsonArray . getDouble ( <NUM_LIT:0> ) , <NUM_LIT> ) ; } public void testElement_index_0_Array ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; ; int [ ] ints = { <NUM_LIT:0> , <NUM_LIT:2> } ; array . element ( <NUM_LIT:0> , ints ) ; Assertions . assertEquals ( JSONArray . fromObject ( ints ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_Boolean ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; ; array . element ( <NUM_LIT:0> , Boolean . TRUE ) ; Assertions . assertTrue ( array . getBoolean ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_Class ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , Object . class ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_JSON ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , JSONNull . getInstance ( ) ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_JSONFunction ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONFunction f = new JSONFunction ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , f ) ; Assertions . assertEquals ( f , ( JSONFunction ) array . get ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_JSONString ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , bean ) ; Assertions . assertEquals ( JSONArray . fromObject ( bean ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_JSONTokener ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONTokener tok = new JSONTokener ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , tok ) ; tok . reset ( ) ; Assertions . assertEquals ( JSONArray . fromObject ( tok ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_Number ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , new Double ( <NUM_LIT:2> ) ) ; Assertions . assertEquals ( new Double ( <NUM_LIT:2> ) . doubleValue ( ) , array . getDouble ( <NUM_LIT:0> ) , <NUM_LIT> ) ; } public void testElement_index_0_Object ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , new BeanA ( ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( new BeanA ( ) ) , array . getJSONObject ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_String ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , "<STR_LIT>" ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_String_JSON ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , "<STR_LIT:[]>" ) ; Assertions . assertEquals ( new JSONArray ( ) . toString ( ) , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_index_0_String_null ( ) { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , ( String ) null ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_index_1_Array ( ) { JSONArray array = new JSONArray ( ) ; int [ ] ints = { <NUM_LIT:1> , <NUM_LIT:2> } ; array . element ( <NUM_LIT:1> , ints ) ; Assertions . assertEquals ( JSONArray . fromObject ( ints ) , array . getJSONArray ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_boolean ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , true ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertTrue ( jsonArray . getBoolean ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_Boolean ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , Boolean . TRUE ) ; Assertions . assertTrue ( array . getBoolean ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_Class ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , Object . class ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_Collection ( ) { List l = new ArrayList ( ) ; l . add ( Boolean . TRUE ) ; l . add ( new Integer ( <NUM_LIT:1> ) ) ; l . add ( "<STR_LIT:string>" ) ; JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , l ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , jsonArray . getJSONArray ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_double ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , <NUM_LIT> ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT> , jsonArray . getDouble ( <NUM_LIT:1> ) , <NUM_LIT> ) ; } public void testElement_index_1_int ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , jsonArray . getInt ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_JSON ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , JSONNull . getInstance ( ) ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_JSONFunction ( ) { JSONArray array = new JSONArray ( ) ; JSONFunction f = new JSONFunction ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:1> , f ) ; Assertions . assertEquals ( f , ( JSONFunction ) array . get ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_JSONString ( ) { JSONArray array = new JSONArray ( ) ; ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:1> , bean ) ; Assertions . assertEquals ( JSONArray . fromObject ( bean ) , array . getJSONArray ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_JSONTokener ( ) { JSONArray array = new JSONArray ( ) ; JSONTokener tok = new JSONTokener ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:1> , tok ) ; tok . reset ( ) ; Assertions . assertEquals ( JSONArray . fromObject ( tok ) , array . getJSONArray ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_long ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , <NUM_LIT:1L> ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1L> , jsonArray . getLong ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , map ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( map ) , jsonArray . getJSONObject ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_Number ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , new Double ( <NUM_LIT:2> ) ) ; Assertions . assertEquals ( new Double ( <NUM_LIT:2> ) . doubleValue ( ) , array . getDouble ( <NUM_LIT:1> ) , <NUM_LIT> ) ; } public void testElement_index_1_Object ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , new BeanA ( ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( new BeanA ( ) ) , array . getJSONObject ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_String ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , "<STR_LIT>" ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_String_JSON ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , "<STR_LIT:[]>" ) ; Assertions . assertEquals ( new JSONArray ( ) . toString ( ) , array . getString ( <NUM_LIT:1> ) ) ; } public void testElement_index_1_String_null ( ) { JSONArray array = new JSONArray ( ) ; array . element ( <NUM_LIT:1> , ( String ) null ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:1> ) ) ; } public void testElement_int ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonArray . getInt ( <NUM_LIT:0> ) ) ; } public void testElement_JSON ( ) { JSONArray array = new JSONArray ( ) ; array . element ( JSONNull . getInstance ( ) ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:0> ) ) ; } public void testElement_JSONFunction ( ) { JSONArray array = new JSONArray ( ) ; JSONFunction f = new JSONFunction ( "<STR_LIT>" ) ; array . element ( f ) ; Assertions . assertEquals ( f , ( JSONFunction ) array . get ( <NUM_LIT:0> ) ) ; } public void testElement_JSONString ( ) { JSONArray array = new JSONArray ( ) ; ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; array . element ( bean ) ; Assertions . assertEquals ( JSONArray . fromObject ( bean ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_JSONTokener ( ) { JSONArray array = new JSONArray ( ) ; JSONTokener tok = new JSONTokener ( "<STR_LIT>" ) ; array . element ( tok ) ; tok . reset ( ) ; Assertions . assertEquals ( JSONArray . fromObject ( tok ) , array . getJSONArray ( <NUM_LIT:0> ) ) ; } public void testElement_long ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1L> ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertEquals ( <NUM_LIT:1L> , jsonArray . getLong ( <NUM_LIT:0> ) ) ; } public void testElement_Map ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( map ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( map ) , jsonArray . getJSONObject ( <NUM_LIT:0> ) ) ; } public void testElement_negativeIndex ( ) { try { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( - <NUM_LIT:1> , JSONNull . getInstance ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testElement_Number ( ) { JSONArray array = new JSONArray ( ) ; array . element ( new Double ( <NUM_LIT:2> ) ) ; Assertions . assertEquals ( new Double ( <NUM_LIT:2> ) . doubleValue ( ) , array . getDouble ( <NUM_LIT:0> ) , <NUM_LIT> ) ; } public void testElement_Object ( ) { JSONArray array = new JSONArray ( ) ; array . element ( new BeanA ( ) ) ; Assertions . assertEquals ( JSONObject . fromObject ( new BeanA ( ) ) , array . getJSONObject ( <NUM_LIT:0> ) ) ; } public void testElement_replace ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( true ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertTrue ( jsonArray . getBoolean ( <NUM_LIT:0> ) ) ; jsonArray . element ( <NUM_LIT:0> , false ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertFalse ( jsonArray . getBoolean ( <NUM_LIT:0> ) ) ; } public void testElement_String ( ) { JSONArray array = new JSONArray ( ) ; array . element ( "<STR_LIT>" ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_String_JSON ( ) { JSONArray array = new JSONArray ( ) ; array . element ( "<STR_LIT:[]>" ) ; Assertions . assertEquals ( new JSONArray ( ) . toString ( ) , array . getString ( <NUM_LIT:0> ) ) ; } public void testElement_String_null ( ) { JSONArray array = new JSONArray ( ) ; array . element ( ( String ) null ) ; Assertions . assertEquals ( "<STR_LIT>" , array . getString ( <NUM_LIT:0> ) ) ; } public void testFromObject_BigDecimal ( ) { JSONArray actual = JSONArray . fromObject ( new BigDecimal ( "<STR_LIT>" ) ) ; assertTrue ( actual . get ( <NUM_LIT:0> ) instanceof BigDecimal ) ; } public void testFromObject_BigInteger ( ) { JSONArray actual = JSONArray . fromObject ( new BigInteger ( "<STR_LIT>" ) ) ; assertTrue ( actual . get ( <NUM_LIT:0> ) instanceof BigInteger ) ; } public void testFromObject_Boolean ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( Boolean . TRUE ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Byte ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Byte ( ( byte ) <NUM_LIT:1> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Double ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Double ( <NUM_LIT> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Float ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Float ( <NUM_LIT> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Integer ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Integer ( <NUM_LIT:1> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_JSONArray ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_JSONFunction ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_JSONString ( ) { ArrayJSONStringBean bean = new ArrayJSONStringBean ( ) ; bean . setValue ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( bean ) ; JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Long ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Long ( <NUM_LIT:1L> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Map ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new HashMap ( ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Short ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new Short ( ( short ) <NUM_LIT:1> ) ) ; Assertions . assertEquals ( expected , actual ) ; } public void testGet_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT:[]>" ) ; jsonArray . get ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( IndexOutOfBoundsException expected ) { } } public void testGetBoolean_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getBoolean ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetBoolean_false ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertFalse ( jsonArray . getBoolean ( <NUM_LIT:0> ) ) ; } public void testGetBoolean_true ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertTrue ( jsonArray . getBoolean ( <NUM_LIT:0> ) ) ; } public void testGetDimensions_empty_array ( ) { int [ ] dims = JSONArray . getDimensions ( new JSONArray ( ) ) ; assertEquals ( <NUM_LIT:1> , dims . length ) ; assertEquals ( <NUM_LIT:0> , dims [ <NUM_LIT:0> ] ) ; } public void testGetDimensions_null_array ( ) { int [ ] dims = JSONArray . getDimensions ( null ) ; assertEquals ( <NUM_LIT:1> , dims . length ) ; assertEquals ( <NUM_LIT:0> , dims [ <NUM_LIT:0> ] ) ; } public void testGetDimensions_one_dimension ( ) { int [ ] dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , dims . length ) ; assertEquals ( <NUM_LIT:3> , dims [ <NUM_LIT:0> ] ) ; } public void testGetDimensions_pyramid ( ) { int [ ] dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:4> , dims . length ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:1> ] ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:2> ] ) ; assertEquals ( <NUM_LIT:1> , dims [ <NUM_LIT:3> ] ) ; dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:4> , dims . length ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:1> ] ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:2> ] ) ; assertEquals ( <NUM_LIT:1> , dims [ <NUM_LIT:3> ] ) ; } public void testGetDimensions_two_dimension ( ) { int [ ] dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , dims . length ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:3> , dims [ <NUM_LIT:1> ] ) ; dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , dims . length ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:3> , dims [ <NUM_LIT:1> ] ) ; dims = JSONArray . getDimensions ( JSONArray . fromObject ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , dims . length ) ; assertEquals ( <NUM_LIT:2> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:3> , dims [ <NUM_LIT:1> ] ) ; } public void testGetDouble_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getDouble ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetDouble_Number ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , jsonArray . getDouble ( <NUM_LIT:0> ) , <NUM_LIT> ) ; } public void testGetDouble_String ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , jsonArray . getDouble ( <NUM_LIT:0> ) , <NUM_LIT> ) ; } public void testGetInt_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getInt ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetInt_Number ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , jsonArray . getInt ( <NUM_LIT:0> ) ) ; } public void testGetInt_String ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , jsonArray . getInt ( <NUM_LIT:0> ) ) ; } public void testGetJSONArray ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) . toString ( ) , jsonArray . getJSONArray ( <NUM_LIT:0> ) . toString ( ) ) ; } public void testGetJSONArray_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getJSONArray ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetJSONObject ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( JSONObject . fromObject ( "<STR_LIT>" ) , jsonArray . getJSONObject ( <NUM_LIT:0> ) ) ; } public void testGetJSONObject_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getJSONObject ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetLong_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . getLong ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testGetLong_Number ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , jsonArray . getLong ( <NUM_LIT:0> ) ) ; } public void testGetLong_String ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , jsonArray . getLong ( <NUM_LIT:0> ) ) ; } public void testGetString ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT:2.0>" , jsonArray . getString ( <NUM_LIT:0> ) ) ; } public void testGetString_exception ( ) { try { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT:[]>" ) ; jsonArray . getString ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( IndexOutOfBoundsException expected ) { } } public void testOptionalGet ( ) { Object [ ] params = new Object [ ] { new JSONArray ( ) , JSONObject . fromObject ( "<STR_LIT>" ) } ; JSONArray jsonArray = JSONArray . fromObject ( params ) ; assertFalse ( jsonArray . optBoolean ( <NUM_LIT:0> ) ) ; assertTrue ( jsonArray . optBoolean ( <NUM_LIT:0> , true ) ) ; assertTrue ( Double . isNaN ( jsonArray . optDouble ( <NUM_LIT:0> ) ) ) ; assertEquals ( <NUM_LIT> , jsonArray . optDouble ( <NUM_LIT:0> , <NUM_LIT> ) , <NUM_LIT> ) ; assertEquals ( <NUM_LIT:0> , jsonArray . optInt ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , jsonArray . optInt ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; assertEquals ( null , jsonArray . optJSONArray ( <NUM_LIT:1> ) ) ; Assertions . assertEquals ( ( JSONArray ) params [ <NUM_LIT:0> ] , jsonArray . optJSONArray ( <NUM_LIT:0> ) ) ; assertEquals ( null , jsonArray . optJSONObject ( <NUM_LIT:0> ) ) ; Assertions . assertEquals ( ( JSONObject ) params [ <NUM_LIT:1> ] , jsonArray . optJSONObject ( <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT:0> , jsonArray . optLong ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , jsonArray . optLong ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , jsonArray . optString ( <NUM_LIT:3> ) ) ; assertEquals ( "<STR_LIT>" , jsonArray . optString ( <NUM_LIT:3> , "<STR_LIT>" ) ) ; } public void testToArray_bean_element ( ) { BeanA [ ] expected = new BeanA [ ] { new BeanA ( ) } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray , BeanA . class ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_BigDecimal ( ) { BigDecimal [ ] expected = new BigDecimal [ ] { MorphUtils . BIGDECIMAL_ZERO , MorphUtils . BIGDECIMAL_ONE } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_BigInteger ( ) { BigInteger [ ] expected = new BigInteger [ ] { BigInteger . ZERO , BigInteger . ONE } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_boolean ( ) { boolean [ ] expected = new boolean [ ] { true , false } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Boolean ( ) { Boolean [ ] expected = new Boolean [ ] { Boolean . TRUE , Boolean . FALSE } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_boolean_multi ( ) { boolean [ ] [ ] expected = new boolean [ ] [ ] { { true , false } , { false , true } } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_byte ( ) { byte [ ] input = new byte [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Byte ( ) { Integer [ ] expected = new Integer [ ] { new Integer ( <NUM_LIT:1> ) , new Integer ( <NUM_LIT:2> ) } ; Byte [ ] bytes = new Byte [ ] { new Byte ( ( byte ) <NUM_LIT:1> ) , new Byte ( ( byte ) <NUM_LIT:2> ) } ; JSONArray jsonArray = JSONArray . fromObject ( bytes ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_byte_multi ( ) { byte [ ] [ ] input = new byte [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; int [ ] [ ] expected = new int [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_char ( ) { String [ ] expected = new String [ ] { "<STR_LIT:A>" , "<STR_LIT:B>" } ; char [ ] input = new char [ ] { '<CHAR_LIT:A>' , '<CHAR_LIT>' } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_char_multi ( ) { String [ ] [ ] expected = new String [ ] [ ] { { "<STR_LIT:a>" , "<STR_LIT:b>" } , { "<STR_LIT:c>" , "<STR_LIT:d>" } } ; char [ ] [ ] input = new char [ ] [ ] { { '<CHAR_LIT:a>' , '<CHAR_LIT:b>' } , { '<CHAR_LIT:c>' , '<CHAR_LIT>' } } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Character ( ) { String [ ] expected = { "<STR_LIT:A>" , "<STR_LIT:B>" } ; Character [ ] chars = new Character [ ] { new Character ( '<CHAR_LIT:A>' ) , new Character ( '<CHAR_LIT>' ) } ; JSONArray jsonArray = JSONArray . fromObject ( chars ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_double ( ) { double [ ] expected = new double [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Double ( ) { Double [ ] expected = new Double [ ] { new Double ( <NUM_LIT> ) , new Double ( <NUM_LIT> ) } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_double_multi ( ) { double [ ] [ ] expected = new double [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_dynabean_element ( ) throws Exception { DynaBean [ ] expected = new DynaBean [ ] { createDynaBean ( ) } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_float ( ) { double [ ] expected = new double [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; float [ ] input = new float [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Float ( ) { Double [ ] expected = new Double [ ] { new Double ( <NUM_LIT> ) , new Double ( <NUM_LIT> ) } ; Float [ ] floats = new Float [ ] { new Float ( <NUM_LIT> ) , new Float ( <NUM_LIT> ) } ; JSONArray jsonArray = JSONArray . fromObject ( floats ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_float_multi ( ) { double [ ] [ ] expected = new double [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; float [ ] [ ] input = new float [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_int ( ) { int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_int_multi ( ) { int [ ] [ ] expected = new int [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Integer ( ) { Integer [ ] expected = new Integer [ ] { new Integer ( <NUM_LIT:1> ) , new Integer ( <NUM_LIT:2> ) } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_long ( ) { long [ ] input = new long [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Long ( ) { Integer [ ] expected = new Integer [ ] { new Integer ( <NUM_LIT:1> ) , new Integer ( <NUM_LIT:2> ) } ; Long [ ] longs = new Long [ ] { new Long ( <NUM_LIT:1L> ) , new Long ( <NUM_LIT> ) } ; JSONArray jsonArray = JSONArray . fromObject ( longs ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_long_multi ( ) { long [ ] [ ] input = new long [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; int [ ] [ ] expected = new int [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Long2 ( ) { Long [ ] expected = new Long [ ] { new Long ( Integer . MAX_VALUE + <NUM_LIT:1L> ) , new Long ( Integer . MAX_VALUE + <NUM_LIT> ) } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_null_elements ( ) { String [ ] expected = new String [ ] { null , null , null } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_short ( ) { short [ ] input = new short [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_Short ( ) { Integer [ ] expected = new Integer [ ] { new Integer ( <NUM_LIT:1> ) , new Integer ( <NUM_LIT:2> ) } ; Short [ ] shorts = new Short [ ] { new Short ( ( short ) <NUM_LIT:1> ) , new Short ( ( short ) <NUM_LIT:2> ) } ; JSONArray jsonArray = JSONArray . fromObject ( shorts ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_short_multi ( ) { short [ ] [ ] input = new short [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; int [ ] [ ] expected = new int [ ] [ ] { { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , { <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_String ( ) { String [ ] expected = new String [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT:6>" } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_String_multi ( ) { String [ ] [ ] expected = new String [ ] [ ] { { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" } , { "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT:6>" } } ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; Object actual = JSONArray . toArray ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_StringToInt ( ) { int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; String [ ] input = new String [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT:6>" } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( Integer . TYPE ) ; Object actual = JSONArray . toArray ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_StringToInteger ( ) { int [ ] expected = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> } ; String [ ] input = new String [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT:6>" } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( Integer . class ) ; Object actual = JSONArray . toArray ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToArray_StringToInteger_empty ( ) { int [ ] expected = new int [ ] { } ; String [ ] input = new String [ ] { } ; JSONArray jsonArray = JSONArray . fromObject ( input ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( Integer . class ) ; Object actual = JSONArray . toArray ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToJSONObject ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONObject expected = JSONObject . fromObject ( "<STR_LIT>" ) ; JSONArray names = JSONArray . fromObject ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , jsonArray . toJSONObject ( names ) ) ; } public void testToJSONObject_null_object ( ) { JSONArray jsonArray = new JSONArray ( ) ; assertNull ( jsonArray . toJSONObject ( null ) ) ; assertNull ( jsonArray . toJSONObject ( new JSONArray ( ) ) ) ; assertNull ( jsonArray . toJSONObject ( JSONArray . fromObject ( "<STR_LIT>" ) ) ) ; } public void testToList_bean_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( new BeanA ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray , BeanA . class ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_BigDecimal ( ) { List expected = new ArrayList ( ) ; expected . add ( MorphUtils . BIGDECIMAL_ZERO ) ; expected . add ( MorphUtils . BIGDECIMAL_ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_BigInteger ( ) { List expected = new ArrayList ( ) ; expected . add ( BigInteger . ZERO ) ; expected . add ( BigInteger . ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Boolean ( ) { List expected = new ArrayList ( ) ; expected . add ( Boolean . TRUE ) ; expected . add ( Boolean . FALSE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Byte ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List bytes = new ArrayList ( ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:1> ) ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( bytes ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Character ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; List chars = new ArrayList ( ) ; chars . add ( new Character ( '<CHAR_LIT:A>' ) ) ; chars . add ( new Character ( '<CHAR_LIT>' ) ) ; JSONArray jsonArray = JSONArray . fromObject ( chars ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Double ( ) { List expected = new ArrayList ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_dynaBean_elements ( ) throws Exception { List expected = new ArrayList ( ) ; expected . add ( createDynaBean ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Float ( ) { List expected = new ArrayList ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; List floats = new ArrayList ( ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( floats ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Integer ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_JSONFunction_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_JSONFunction_elements_2 ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT>" ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Long ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List longs = new ArrayList ( ) ; longs . add ( new Long ( <NUM_LIT:1L> ) ) ; longs . add ( new Long ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( longs ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Long2 ( ) { List expected = new ArrayList ( ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT:1L> ) ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_null_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( null ) ; expected . add ( null ) ; expected . add ( null ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Short ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List shorts = new ArrayList ( ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:1> ) ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( shorts ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_String ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_String_multi ( ) { List a = new ArrayList ( ) ; a . add ( "<STR_LIT:a>" ) ; a . add ( "<STR_LIT:b>" ) ; List b = new ArrayList ( ) ; b . add ( "<STR_LIT:1>" ) ; b . add ( "<STR_LIT:2>" ) ; List expected = new ArrayList ( ) ; expected . add ( a ) ; expected . add ( b ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = JSONArray . toList ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testWrite ( ) throws IOException { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; StringWriter sw = new StringWriter ( ) ; jsonArray . write ( sw ) ; assertEquals ( "<STR_LIT>" , sw . toString ( ) ) ; } private MorphDynaBean createDynaBean ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT:name>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT:name>" , "<STR_LIT>" ) ; return dynaBean ; } private void testJSONArray ( Object array , String expected ) { try { JSONArray jsonArray = JSONArray . fromObject ( array ) ; assertEquals ( expected , jsonArray . toString ( ) ) ; } catch ( JSONException jsone ) { fail ( jsone . getMessage ( ) ) ; } } } </s>
<s> package net . sf . json ; public class TestJSONObjectStaticBuilders_JSONString extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_JSONString . class ) ; } public TestJSONObjectStaticBuilders_JSONString ( String name ) { super ( name ) ; } protected Object getSource ( ) { return new JsonBean ( ) ; } public static class JsonBean implements JSONString { public String toJSONString ( ) { return "<STR_LIT>" ; } } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; public class TestJSONObjectStaticBuilders_DynaBean extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_DynaBean . class ) ; } public TestJSONObjectStaticBuilders_DynaBean ( String name ) { super ( name ) ; } protected Object getSource ( ) { Map map = new HashMap ( ) ; String [ ] props = getProperties ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { map . put ( props [ i ] , PropertyConstants . getPropertyClass ( props [ i ] ) ) ; } map . put ( "<STR_LIT:class>" , Class . class ) ; map . put ( "<STR_LIT>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( map ) ; MorphDynaBean dynaBean = null ; try { dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { dynaBean . set ( props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } dynaBean . set ( "<STR_LIT:class>" , Object . class ) ; dynaBean . set ( "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return dynaBean ; } } </s>
<s> package net . sf . json ; import java . lang . reflect . InvocationTargetException ; import java . util . ArrayList ; import java . util . Calendar ; import java . util . Date ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . ListIterator ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . ezmorph . object . MapToDateMorpher ; import net . sf . json . sample . ArrayBean ; import net . sf . json . sample . BeanA ; import net . sf . json . sample . BeanA1763699 ; import net . sf . json . sample . BeanB1763699 ; import net . sf . json . sample . BeanC ; import net . sf . json . sample . ChildBean ; import net . sf . json . sample . DateBean ; import net . sf . json . sample . FieldBean ; import net . sf . json . sample . IdBean ; import net . sf . json . sample . InterfaceBean ; import net . sf . json . sample . JSONTestBean ; import net . sf . json . sample . ListingBean ; import net . sf . json . sample . MappedBean ; import net . sf . json . sample . Media ; import net . sf . json . sample . MediaBean ; import net . sf . json . sample . MediaList ; import net . sf . json . sample . MediaListBean ; import net . sf . json . sample . NumberArrayBean ; import net . sf . json . sample . PackageProtectedBean ; import net . sf . json . sample . ParentBean ; import net . sf . json . sample . Player ; import net . sf . json . sample . PlayerList ; import net . sf . json . sample . PrimitiveBean ; import net . sf . json . sample . PrivateConstructorBean ; import net . sf . json . sample . UnstandardBean ; import net . sf . json . sample . UnstandardBeanInstanceStrategy ; import net . sf . json . util . JSONUtils ; import net . sf . json . util . JavaIdentifierTransformer ; import net . sf . json . util . JsonEventListener ; import org . apache . commons . beanutils . DynaBean ; import org . apache . commons . beanutils . PropertyUtils ; public class TestUserSubmitted extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestUserSubmitted . class ) ; } private JsonConfig jsonConfig ; public TestUserSubmitted ( String name ) { super ( name ) ; } public void testPatch_2929940 ( ) { Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , Long . class ) ; ListingBean original = new ListingBean ( ) ; original . addAttribute ( Long . valueOf ( <NUM_LIT:12> ) ) ; JSONObject jsonObject = JSONObject . fromObject ( JSONObject . fromObject ( original ) . toString ( ) ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( ListingBean . class ) ; jsonConfig . setClassMap ( classMap ) ; ListingBean bean = ( ListingBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertTrue ( bean . getAttributes ( ) . get ( <NUM_LIT:0> ) instanceof Long ) ; } public void testBug_1635890 ( ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { String TEST_JSON_STRING = "<STR_LIT>" ; DynaBean jsonBean = ( DynaBean ) JSONObject . toBean ( JSONObject . fromObject ( TEST_JSON_STRING ) ) ; assertNotNull ( jsonBean ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , jsonBean . get ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonBean . get ( "<STR_LIT>" ) ) ; DynaBean jsonRateBreakdownBean = ( DynaBean ) jsonBean . get ( "<STR_LIT>" ) ; assertNotNull ( "<STR_LIT>" , jsonRateBreakdownBean ) ; Object jsonRateBean = jsonRateBreakdownBean . get ( "<STR_LIT>" ) ; assertNotNull ( "<STR_LIT>" , jsonRateBean ) ; assertTrue ( "<STR_LIT:list>" , jsonRateBean instanceof ArrayList ) ; assertNotNull ( "<STR_LIT>" , jsonRateBreakdownBean . get ( "<STR_LIT>" , <NUM_LIT:0> ) ) ; } public void testBug_1650535_builders ( ) { String json = "<STR_LIT>" ; JSONObject object = JSONObject . fromObject ( json ) ; assertNotNull ( object ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; Object obj = object . get ( "<STR_LIT>" ) ; assertTrue ( obj instanceof String ) ; Object array = object . get ( "<STR_LIT>" ) ; assertTrue ( array instanceof String ) ; json = "<STR_LIT>" ; object = JSONObject . fromObject ( json ) ; assertNotNull ( object ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; obj = object . get ( "<STR_LIT>" ) ; assertTrue ( obj instanceof String ) ; array = object . get ( "<STR_LIT>" ) ; assertTrue ( array instanceof String ) ; json = "<STR_LIT>" ; JSONArray jarray = JSONArray . fromObject ( json ) ; assertNotNull ( jarray ) ; obj = jarray . get ( <NUM_LIT:0> ) ; assertTrue ( obj instanceof String ) ; array = jarray . get ( <NUM_LIT:1> ) ; assertTrue ( array instanceof String ) ; json = "<STR_LIT>" ; jarray = JSONArray . fromObject ( json ) ; assertNotNull ( jarray ) ; obj = jarray . get ( <NUM_LIT:0> ) ; assertTrue ( obj instanceof String ) ; array = jarray . get ( <NUM_LIT:1> ) ; assertTrue ( array instanceof String ) ; Map map = new HashMap ( ) ; map . put ( "<STR_LIT:address>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; object = JSONObject . fromObject ( map ) ; assertNotNull ( object ) ; assertTrue ( object . has ( "<STR_LIT:address>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . has ( "<STR_LIT>" ) ) ; assertTrue ( object . get ( "<STR_LIT:address>" ) instanceof String ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; } public void testBug_1650535_setters ( ) { JSONObject object = new JSONObject ( ) ; object . element ( "<STR_LIT>" , "<STR_LIT:{}>" ) ; object . element ( "<STR_LIT>" , "<STR_LIT>" ) ; object . element ( "<STR_LIT>" , "<STR_LIT:[]>" ) ; object . element ( "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof JSONObject ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof JSONArray ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; object . element ( "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( object . get ( "<STR_LIT>" ) instanceof String ) ; } public void testBug_1753528_ArrayStringLiteralToString ( ) { BeanA bean = new BeanA ( ) ; bean . setString ( "<STR_LIT>" ) ; JSONObject jsonObject = JSONObject . fromObject ( bean ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT:string>" ) ) ; bean . setString ( "<STR_LIT>" ) ; jsonObject = JSONObject . fromObject ( bean ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT:string>" ) ) ; } public void testBug_1763699_toBean ( ) { JSONObject json = JSONObject . fromObject ( "<STR_LIT>" ) ; BeanA1763699 bean = ( BeanA1763699 ) JSONObject . toBean ( json , BeanA1763699 . class ) ; assertNotNull ( bean ) ; BeanB1763699 [ ] bbeans = bean . getBbeans ( ) ; assertNotNull ( bbeans ) ; assertEquals ( <NUM_LIT:1> , bbeans . length ) ; assertEquals ( "<STR_LIT:test>" , bbeans [ <NUM_LIT:0> ] . getStr ( ) ) ; } public void testBug_1764768_toBean ( ) { JSONObject json = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , BeanA . class ) ; BeanC bean = ( BeanC ) JSONObject . toBean ( json , BeanC . class , classMap ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getBeanA ( ) ) ; assertEquals ( new BeanA ( ) , bean . getBeanA ( ) ) ; } public void testBug_1769559_array_conversion ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , new JSONArray ( ) . element ( "<STR_LIT:{}>" ) . element ( "<STR_LIT>" ) ) ; ArrayBean bean = ( ArrayBean ) JSONObject . toBean ( jsonObject , ArrayBean . class ) ; assertNotNull ( bean ) ; JSONArray jsonArray = jsonObject . getJSONArray ( "<STR_LIT>" ) ; BeanA [ ] beans = ( BeanA [ ] ) JSONArray . toArray ( jsonArray , BeanA . class ) ; assertNotNull ( beans ) ; assertEquals ( <NUM_LIT:2> , beans . length ) ; assertEquals ( new BeanA ( ) , beans [ <NUM_LIT:0> ] ) ; assertEquals ( new BeanA ( false , <NUM_LIT> , "<STR_LIT>" ) , beans [ <NUM_LIT:1> ] ) ; } public void testBug_1769578_array_conversion ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , MediaBean . class ) ; MediaListBean bean = ( MediaListBean ) JSONObject . toBean ( jsonObject , MediaListBean . class , classMap ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getMedia ( ) ) ; assertTrue ( bean . getMedia ( ) . getClass ( ) . isArray ( ) ) ; Object [ ] media = ( Object [ ] ) bean . getMedia ( ) ; assertEquals ( <NUM_LIT:2> , media . length ) ; Object mediaItem1 = media [ <NUM_LIT:0> ] ; assertTrue ( mediaItem1 instanceof MediaBean ) ; assertEquals ( "<STR_LIT>" , ( ( MediaBean ) mediaItem1 ) . getTitle ( ) ) ; } public void testBug_1812682 ( ) { int [ ] numbers = new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> } ; JSONObject json = new JSONObject ( ) . element ( "<STR_LIT>" , numbers ) . element ( "<STR_LIT>" , numbers ) . element ( "<STR_LIT>" , numbers ) . element ( "<STR_LIT>" , numbers ) . element ( "<STR_LIT>" , numbers ) . element ( "<STR_LIT>" , numbers ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( NumberArrayBean . class ) ; NumberArrayBean bean = ( NumberArrayBean ) JSONObject . toBean ( json , jsonConfig ) ; assertNotNull ( bean ) ; } public void testBug_1813301 ( ) { List list = new ArrayList ( ) ; list . add ( "<STR_LIT:1>" ) ; list . add ( "<STR_LIT:2>" ) ; list . add ( "<STR_LIT:3>" ) ; JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:name>" , "<STR_LIT>" ) . element ( "<STR_LIT:list>" , list ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( MappedBean . class ) ; MappedBean bean = ( MappedBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( "<STR_LIT>" , bean . getName ( ) ) ; Assertions . assertEquals ( list , bean . getList ( ) ) ; } public void testBug_1875600_1 ( ) { JSONArray jArray = JSONArray . fromObject ( "<STR_LIT:[]>" ) ; int [ ] iArray = ( int [ ] ) JSONArray . toArray ( jArray , int . class ) ; JSONArray actual = JSONArray . fromObject ( iArray ) ; Assertions . assertEquals ( new JSONArray ( ) , actual ) ; } public void testBug_1875600_2 ( ) { JSONArray jArray = JSONArray . fromObject ( "<STR_LIT>" ) ; int [ ] [ ] iArray = ( int [ ] [ ] ) JSONArray . toArray ( jArray , int . class ) ; JSONArray actual = JSONArray . fromObject ( iArray ) ; Assertions . assertEquals ( new JSONArray ( ) . element ( new JSONArray ( ) ) , actual ) ; } public void testConstructor_Object__nullArray ( ) { String [ ] strarr = null ; JSONObject jsonObject = JSONObject . fromObject ( strarr , jsonConfig ) ; assertTrue ( jsonObject . isNullObject ( ) ) ; } public void testConstructor_Object_EnclosedArray ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; bean . setOarray ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertFalse ( jsonObject . isNullObject ( ) ) ; assertFalse ( jsonObject . getJSONArray ( "<STR_LIT>" ) . isEmpty ( ) ) ; } public void testConstructor_Object_EnclosedNullArray ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; bean . setOarray ( null ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertFalse ( jsonObject . isNullObject ( ) ) ; assertTrue ( jsonObject . getJSONArray ( "<STR_LIT>" ) . isEmpty ( ) ) ; } public void testConstructorAndToBean_Object_RoundTrip_EnclosedNullArray ( ) { PrimitiveBean bean = new PrimitiveBean ( ) ; bean . setOarray ( null ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; PrimitiveBean bean2 = ( PrimitiveBean ) JSONObject . toBean ( jsonObject , PrimitiveBean . class ) ; assertNotNull ( bean2 ) ; assertEquals ( <NUM_LIT:0> , bean2 . getOarray ( ) . length ) ; } public void testDynaBeanAttributeMap ( ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { JSONObject jsonObject = JSONObject . fromObject ( new JSONTestBean ( ) ) ; String jsonString = jsonObject . toString ( ) ; DynaBean jsonBean = ( DynaBean ) JSONObject . toBean ( JSONObject . fromObject ( jsonString ) ) ; assertNotNull ( jsonBean ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , jsonBean . get ( "<STR_LIT>" ) ) ; } public void testFR_1768960_array_conversion ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , MediaBean . class ) ; MediaListBean bean = ( MediaListBean ) JSONObject . toBean ( jsonObject , MediaListBean . class , classMap ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getMedia2 ( ) ) ; List media2 = bean . getMedia2 ( ) ; assertEquals ( <NUM_LIT:2> , media2 . size ( ) ) ; Object mediaItem1 = media2 . get ( <NUM_LIT:0> ) ; assertTrue ( mediaItem1 instanceof MediaBean ) ; assertEquals ( "<STR_LIT>" , ( ( MediaBean ) mediaItem1 ) . getTitle ( ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; bean = ( MediaListBean ) JSONObject . toBean ( jsonObject , MediaListBean . class , classMap ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getMedia2 ( ) ) ; media2 = bean . getMedia2 ( ) ; assertEquals ( <NUM_LIT:1> , media2 . size ( ) ) ; mediaItem1 = media2 . get ( <NUM_LIT:0> ) ; assertTrue ( mediaItem1 instanceof MediaBean ) ; assertEquals ( "<STR_LIT>" , ( ( MediaBean ) mediaItem1 ) . getTitle ( ) ) ; } public void testFR_1808430_newBeanInstance ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setNewBeanInstanceStrategy ( new UnstandardBeanInstanceStrategy ( ) ) ; JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:id>" , <NUM_LIT:1> ) ; jsonConfig . setRootClass ( UnstandardBean . class ) ; UnstandardBean bean = ( UnstandardBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( UnstandardBean . class , bean . getClass ( ) ) ; assertEquals ( <NUM_LIT:1> , bean . getId ( ) ) ; } public void testFR_1832047_packageProtectedBean ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:value>" , "<STR_LIT>" ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( PackageProtectedBean . class ) ; PackageProtectedBean bean = ( PackageProtectedBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( <NUM_LIT> , bean . getValue ( ) ) ; } public void testFR_1832047_privateProtectedBean ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:value>" , "<STR_LIT>" ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( PrivateConstructorBean . class ) ; PrivateConstructorBean bean = ( PrivateConstructorBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertEquals ( <NUM_LIT> , bean . getValue ( ) ) ; } public void testFR_1858073_preserveInsertionOrder ( ) { JSONObject jsonObject = new JSONObject ( ) . element ( "<STR_LIT:one>" , "<STR_LIT:one>" ) . element ( "<STR_LIT:two>" , "<STR_LIT:two>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; JSONArray actual = jsonObject . names ( ) ; JSONArray expected = new JSONArray ( ) . element ( "<STR_LIT:one>" ) . element ( "<STR_LIT:two>" ) . element ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObjectCurliesOnString ( ) { String json = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( json ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT:1> , jsonObject . size ( ) ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT>" ) ) ; json = "<STR_LIT>" ; jsonObject = JSONObject . fromObject ( json ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT:1> , jsonObject . size ( ) ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT>" ) ) ; json = "<STR_LIT>" ; jsonObject = JSONObject . fromObject ( json ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT:1> , jsonObject . size ( ) ) ; assertEquals ( "<STR_LIT>" , jsonObject . get ( "<STR_LIT>" ) ) ; } public void testHandleJettisonEmptyElement ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; jsonConfig . setHandleJettisonEmptyElement ( true ) ; jsonConfig . setRootClass ( BeanC . class ) ; BeanC bean = ( BeanC ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertNull ( bean . getBeanA ( ) ) ; assertNull ( bean . getBeanB ( ) ) ; } public void testHandleJettisonSingleElementArray ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , MediaBean . class ) ; jsonConfig . setHandleJettisonSingleElementArray ( true ) ; jsonConfig . setRootClass ( MediaListBean . class ) ; jsonConfig . setClassMap ( classMap ) ; MediaListBean bean = ( MediaListBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getMedia2 ( ) ) ; List media2 = bean . getMedia2 ( ) ; assertEquals ( <NUM_LIT:1> , media2 . size ( ) ) ; Object mediaItem1 = media2 . get ( <NUM_LIT:0> ) ; assertTrue ( mediaItem1 instanceof MediaBean ) ; assertEquals ( "<STR_LIT>" , ( ( MediaBean ) mediaItem1 ) . getTitle ( ) ) ; } public void testHandleJettisonSingleElementArray2 ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , Media . class ) ; classMap . put ( "<STR_LIT>" , MediaList . class ) ; jsonConfig . setHandleJettisonSingleElementArray ( true ) ; jsonConfig . setRootClass ( Player . class ) ; jsonConfig . setClassMap ( classMap ) ; Player bean = ( Player ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getMediaList ( ) ) ; MediaList mediaList = bean . getMediaList ( ) ; assertNotNull ( mediaList . getMedia ( ) ) ; ArrayList medias = mediaList . getMedia ( ) ; assertEquals ( "<STR_LIT>" , ( ( Media ) medias . get ( <NUM_LIT:0> ) ) . getTitle ( ) ) ; } public void testHandleJettisonSingleElementArray3 ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , Media . class ) ; classMap . put ( "<STR_LIT>" , MediaList . class ) ; classMap . put ( "<STR_LIT>" , Player . class ) ; jsonConfig . setHandleJettisonSingleElementArray ( true ) ; jsonConfig . setRootClass ( PlayerList . class ) ; jsonConfig . setClassMap ( classMap ) ; PlayerList bean = ( PlayerList ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getPlayer ( ) ) ; ArrayList players = bean . getPlayer ( ) ; assertNotNull ( players ) ; assertNotNull ( players . get ( <NUM_LIT:0> ) ) ; Player player = ( Player ) players . get ( <NUM_LIT:0> ) ; assertNotNull ( player . getMediaList ( ) ) ; MediaList mediaList = player . getMediaList ( ) ; assertNotNull ( mediaList . getMedia ( ) ) ; ArrayList medias = mediaList . getMedia ( ) ; assertEquals ( "<STR_LIT>" , ( ( Media ) medias . get ( <NUM_LIT:0> ) ) . getTitle ( ) ) ; } public void testJsonWithNamespaceToDynaBean ( ) throws Exception { jsonConfig . setJavaIdentifierTransformer ( JavaIdentifierTransformer . NOOP ) ; String str = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" + "<STR_LIT:}>" + "<STR_LIT>" + "<STR_LIT>" ; JSONObject json = JSONObject . fromObject ( str , jsonConfig ) ; Object bean = JSONObject . toBean ( ( JSONObject ) json ) ; assertNotNull ( bean ) ; List params = ( List ) PropertyUtils . getProperty ( bean , "<STR_LIT>" ) ; DynaBean param0 = ( DynaBean ) params . get ( <NUM_LIT:0> ) ; DynaBean itemLookup = ( DynaBean ) param0 . get ( "<STR_LIT>" ) ; assertNotNull ( itemLookup ) ; assertEquals ( "<STR_LIT>" , itemLookup . get ( "<STR_LIT>" ) ) ; } public void testToBeanSimpleToComplexValueTransformation ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; IdBean idBean = ( IdBean ) JSONObject . toBean ( jsonObject , IdBean . class ) ; assertNotNull ( idBean ) ; assertEquals ( null , idBean . getId ( ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; idBean = ( IdBean ) JSONObject . toBean ( jsonObject , IdBean . class ) ; assertNotNull ( idBean ) ; assertNotNull ( idBean . getId ( ) ) ; assertEquals ( <NUM_LIT> , idBean . getId ( ) . getValue ( ) ) ; JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new IdBean . IdMorpher ( ) , true ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; idBean = ( IdBean ) JSONObject . toBean ( jsonObject , IdBean . class ) ; assertNotNull ( idBean ) ; assertEquals ( new IdBean . Id ( <NUM_LIT:1L> ) , idBean . getId ( ) ) ; } public void testToBeanWithMultipleMorphersForTargetType ( ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DATE , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; Date date = c . getTime ( ) ; DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; JSONObject jsonObject = JSONObject . fromObject ( bean ) ; JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new MapToDateMorpher ( ) ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( DateBean . class ) ; DateBean actual = ( DateBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; Calendar d = Calendar . getInstance ( ) ; d . setTime ( actual . getDate ( ) ) ; assertEquals ( c . get ( Calendar . YEAR ) , d . get ( Calendar . YEAR ) ) ; assertEquals ( c . get ( Calendar . MONTH ) , d . get ( Calendar . MONTH ) ) ; assertEquals ( c . get ( Calendar . DATE ) , d . get ( Calendar . DATE ) ) ; assertEquals ( c . get ( Calendar . HOUR_OF_DAY ) , d . get ( Calendar . HOUR_OF_DAY ) ) ; assertEquals ( c . get ( Calendar . MINUTE ) , d . get ( Calendar . MINUTE ) ) ; assertEquals ( c . get ( Calendar . SECOND ) , d . get ( Calendar . SECOND ) ) ; assertEquals ( c . get ( Calendar . MILLISECOND ) , d . get ( Calendar . MILLISECOND ) ) ; } public void testToBeanWithInterfaceField ( ) { JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( InterfaceBean . class ) ; Map classMap = new HashMap ( ) ; classMap . put ( "<STR_LIT>" , RunnableImpl . class ) ; jsonConfig . setClassMap ( classMap ) ; InterfaceBean bean = ( InterfaceBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean ) ; assertNotNull ( bean . getRunnable ( ) ) ; assertTrue ( bean . getRunnable ( ) instanceof RunnableImpl ) ; } public void testCycleDetection_withExclusions ( ) { ParentBean parent = new ParentBean ( ) ; parent . setChild ( new ChildBean ( ) ) ; jsonConfig . setExcludes ( new String [ ] { "<STR_LIT>" } ) ; JSONObject . fromObject ( parent , jsonConfig ) ; } public void testJSONArrayIterator ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . add ( "<STR_LIT:1>" ) ; jsonArray . add ( "<STR_LIT:2>" ) ; jsonArray . add ( "<STR_LIT:3>" ) ; List list = new LinkedList ( ) ; list . add ( "<STR_LIT:4>" ) ; list . add ( "<STR_LIT:5>" ) ; list . add ( "<STR_LIT:6>" ) ; jsonArray . add ( list ) ; List newList = new LinkedList ( ) ; newList . add ( "<STR_LIT>" ) ; newList . add ( "<STR_LIT>" ) ; newList . add ( "<STR_LIT>" ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , jsonArray ) ; ListIterator listIterator = jsonArray . listIterator ( ) ; listIterator . add ( newList ) ; Assertions . assertEquals ( JSONArray . fromObject ( "<STR_LIT>" ) , jsonArray ) ; } public void testJSONArray_badFormattedString ( ) { String badJson = "<STR_LIT>" ; try { JSONArray . fromObject ( badJson ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException jsone ) { assertTrue ( jsone . getMessage ( ) . startsWith ( "<STR_LIT>" ) ) ; } } public void testJSONObject_badFormattedString ( ) { String badJson = "<STR_LIT>" ; try { JSONObject . fromObject ( badJson ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException jsone ) { assertTrue ( jsone . getMessage ( ) . startsWith ( "<STR_LIT>" ) ) ; } } public void testQuotedFunctions ( ) { JSONObject json = JSONObject . fromObject ( "<STR_LIT>" ) ; assertTrue ( json . get ( "<STR_LIT>" ) instanceof String ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; } public void testJsonWithNullKeys ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ; map . put ( null , "<STR_LIT>" ) ; Object [ ] obj = { map } ; try { JSONSerializer . toJSON ( obj ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testJsonWithNullKeys2 ( ) { Map map = new HashMap ( ) ; map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ; map . put ( null , "<STR_LIT>" ) ; try { System . err . println ( JSONSerializer . toJSON ( map ) ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testJSONArray_JavascriptCompliant ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJavascriptCompliant ( true ) ; String json = "<STR_LIT>" ; JSONArray array = JSONArray . fromObject ( json , jsonConfig ) ; assertNotNull ( array ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:1> ) ) ; } public void testJSONArray_JavascriptComplian2t ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJavascriptCompliant ( true ) ; JSONArray array = new JSONArray ( ) ; array . element ( "<STR_LIT:null>" , jsonConfig ) ; array . element ( "<STR_LIT>" , jsonConfig ) ; assertNotNull ( array ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:0> ) ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , array . get ( <NUM_LIT:1> ) ) ; } public void testJSONObject_JavascriptCompliant ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJavascriptCompliant ( true ) ; String json = "<STR_LIT>" ; JSONObject object = JSONObject . fromObject ( json , jsonConfig ) ; assertNotNull ( object ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , object . get ( "<STR_LIT>" ) ) ; } public void testJSONObject_JavascriptCompliant2 ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setJavascriptCompliant ( true ) ; JSONObject object = new JSONObject ( ) ; object . element ( "<STR_LIT:key1>" , "<STR_LIT:null>" , jsonConfig ) ; object . element ( "<STR_LIT>" , "<STR_LIT>" , jsonConfig ) ; assertNotNull ( object ) ; Assertions . assertEquals ( JSONNull . getInstance ( ) , object . get ( "<STR_LIT>" ) ) ; } public void testJSONObject_fromObject_FieldBean ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setIgnorePublicFields ( false ) ; FieldBean bean = new FieldBean ( ) ; bean . setValue ( <NUM_LIT> ) ; bean . string = "<STR_LIT>" ; JSONObject jsonObject = JSONObject . fromObject ( bean ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; assertFalse ( jsonObject . has ( "<STR_LIT:string>" ) ) ; jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; assertEquals ( "<STR_LIT>" , jsonObject . getString ( "<STR_LIT:string>" ) ) ; } public void testJSONObject_toBean_FieldBean ( ) { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT:value>" , <NUM_LIT> ) ; jsonObject . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; FieldBean bean1 = ( FieldBean ) JSONObject . toBean ( jsonObject , FieldBean . class ) ; assertNotNull ( bean1 ) ; assertEquals ( <NUM_LIT> , bean1 . getValue ( ) ) ; assertNull ( bean1 . string ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setIgnorePublicFields ( false ) ; jsonConfig . setRootClass ( FieldBean . class ) ; FieldBean bean2 = ( FieldBean ) JSONObject . toBean ( jsonObject , jsonConfig ) ; assertNotNull ( bean2 ) ; assertEquals ( <NUM_LIT> , bean1 . getValue ( ) ) ; assertEquals ( "<STR_LIT>" , bean2 . string ) ; } public void testBug_2692698 ( ) { String input = "<STR_LIT>" ; JSON json = JSONArray . fromObject ( input ) ; String output = json . toString ( ) ; assertEquals ( input , output ) ; } public void testWithoutAnyTroubleTheyMayBeAlreadyDoneByOtherTest ( ) { JsonConfig tConfig = new JsonConfig ( ) ; tConfig . enableEventTriggering ( ) ; tConfig . addJsonEventListener ( new JsonErrorDetector ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT:string>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optString ( "<STR_LIT:string>" ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , jsonObject . get ( "<STR_LIT:string>" ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:10> , jsonObject . optInt ( "<STR_LIT>" ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT:double>" ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , jsonObject . optDouble ( "<STR_LIT:double>" ) , <NUM_LIT> ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT:boolean>" ) ) ; assertEquals ( "<STR_LIT>" , true , jsonObject . optBoolean ( "<STR_LIT:boolean>" ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optJSONArray ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:a>" , jsonObject . optJSONArray ( "<STR_LIT>" ) . optString ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:b>" , jsonObject . optJSONArray ( "<STR_LIT>" ) . optString ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:c>" , jsonObject . optJSONArray ( "<STR_LIT>" ) . optString ( <NUM_LIT:2> ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optJSONArray ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , jsonObject . optJSONArray ( "<STR_LIT>" ) . optInt ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , jsonObject . optJSONArray ( "<STR_LIT>" ) . optInt ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , jsonObject . optJSONArray ( "<STR_LIT>" ) . optInt ( <NUM_LIT:2> ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optJSONArray ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , jsonObject . optJSONArray ( "<STR_LIT>" ) . optBoolean ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , false , jsonObject . optJSONArray ( "<STR_LIT>" ) . optBoolean ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , true , jsonObject . optJSONArray ( "<STR_LIT>" ) . optBoolean ( <NUM_LIT:2> ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optJSONArray ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:a>" , jsonObject . optJSONArray ( "<STR_LIT>" ) . optString ( <NUM_LIT:0> ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" , tConfig ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optString ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , jsonObject . get ( "<STR_LIT>" ) ) ; jsonObject = JSONObject . fromObject ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , jsonObject . containsKey ( "<STR_LIT>" ) ) ; assertNotNull ( "<STR_LIT>" , jsonObject . optString ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , jsonObject . get ( "<STR_LIT>" ) ) ; } public void testBug_2893329 ( ) { String jsonStr = "<STR_LIT>" ; JSONObject json = JSONObject . fromObject ( jsonStr ) ; assertEquals ( "<STR_LIT>" , json . getString ( "<STR_LIT:x>" ) ) ; } public void testBug_3047519 ( ) { String jsonStr = "<STR_LIT>" ; JSONObject json = JSONObject . fromObject ( jsonStr ) ; Object data = json . get ( "<STR_LIT:data>" ) ; assertTrue ( data instanceof String ) ; assertEquals ( "<STR_LIT>" , data ) ; } public static class RunnableImpl implements Runnable { public void run ( ) { } } public static class JsonErrorDetector implements JsonEventListener { public void onArrayEnd ( ) { } public void onArrayStart ( ) { } public void onElementAdded ( int index , Object element ) { } public void onError ( JSONException jsone ) { fail ( "<STR_LIT>" + jsone . getMessage ( ) ) ; } public void onObjectEnd ( ) { } public void onObjectStart ( ) { } public void onPropertySet ( String key , Object value , boolean accumulated ) { } public void onWarning ( String warning ) { } } protected void setUp ( ) throws Exception { super . setUp ( ) ; jsonConfig = new JsonConfig ( ) ; } } </s>
<s> package net . sf . json . regexp ; public class TestJdkRegexpMatcher extends AbstractRegexpMatcherTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJdkRegexpMatcher . class ) ; } public TestJdkRegexpMatcher ( String name ) { super ( name ) ; } protected RegexpMatcher getRegexpMatcher ( String pattern ) { return new JdkRegexpMatcher ( pattern ) ; } } </s>
<s> package net . sf . json . regexp ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestJdkRegexpMatcher . class ) ) ; suite . addTest ( new TestSuite ( TestPerl5RegexpMatcher . class ) ) ; return suite ; } } </s>
<s> package net . sf . json . regexp ; import junit . framework . TestCase ; public abstract class AbstractRegexpMatcherTestCase extends TestCase { public AbstractRegexpMatcherTestCase ( String name ) { super ( name ) ; } public void testGetGroupIfMatches ( ) { RegexpMatcher regexpMatcher = getRegexpMatcher ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT:123>" , regexpMatcher . getGroupIfMatches ( "<STR_LIT>" , <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , regexpMatcher . getGroupIfMatches ( "<STR_LIT>" , <NUM_LIT:1> ) ) ; } public void testMatches ( ) { assertTrue ( getRegexpMatcher ( "<STR_LIT>" ) . matches ( "<STR_LIT>" ) ) ; assertTrue ( getRegexpMatcher ( "<STR_LIT>" ) . matches ( "<STR_LIT>" ) ) ; assertFalse ( getRegexpMatcher ( "<STR_LIT>" ) . matches ( "<STR_LIT>" ) ) ; } protected abstract RegexpMatcher getRegexpMatcher ( String pattern ) ; } </s>
<s> package net . sf . json . regexp ; public class TestPerl5RegexpMatcher extends AbstractRegexpMatcherTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestPerl5RegexpMatcher . class ) ; } public TestPerl5RegexpMatcher ( String name ) { super ( name ) ; } protected RegexpMatcher getRegexpMatcher ( String pattern ) { return new Perl5RegexpMatcher ( pattern ) ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; public class TestJSONObjectEqualsHashCodeCompareTo extends TestCase { private static JSONObject strings ; private static Map values = new HashMap ( ) ; private static JSONObject values1 ; private static JSONObject values2 ; private static JSONObject values3 ; static { values . put ( "<STR_LIT>" , new JSONObject ( true ) ) ; values . put ( "<STR_LIT>" , new JSONObject ( true ) ) ; values . put ( "<STR_LIT>" , Integer . valueOf ( "<STR_LIT:1>" ) ) ; values . put ( "<STR_LIT>" , Integer . valueOf ( "<STR_LIT:2>" ) ) ; values . put ( "<STR_LIT>" , Long . valueOf ( "<STR_LIT:1>" ) ) ; values . put ( "<STR_LIT>" , Long . valueOf ( "<STR_LIT:2>" ) ) ; values . put ( "<STR_LIT>" , "<STR_LIT:1>" ) ; values . put ( "<STR_LIT>" , "<STR_LIT:2>" ) ; values . put ( "<STR_LIT>" , Boolean . TRUE ) ; values . put ( "<STR_LIT>" , Boolean . FALSE ) ; strings = new JSONObject ( ) . element ( "<STR_LIT:int>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:long>" , "<STR_LIT:1>" ) . element ( "<STR_LIT:boolean>" , "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" , "<STR_LIT:string>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; values . put ( "<STR_LIT>" , strings ) ; values1 = new JSONObject ( ) . element ( "<STR_LIT:int>" , Integer . valueOf ( "<STR_LIT:1>" ) ) . element ( "<STR_LIT:long>" , Long . valueOf ( "<STR_LIT:1>" ) ) . element ( "<STR_LIT:boolean>" , Boolean . TRUE ) . element ( "<STR_LIT:string>" , "<STR_LIT:string>" ) . element ( "<STR_LIT>" , new JSONFunction ( "<STR_LIT>" ) ) . element ( "<STR_LIT>" , JSONArray . fromObject ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } ) ) ; values . put ( "<STR_LIT>" , values1 ) ; values2 = new JSONObject ( ) . element ( "<STR_LIT:int>" , Integer . valueOf ( "<STR_LIT:1>" ) ) . element ( "<STR_LIT:long>" , Long . valueOf ( "<STR_LIT:1>" ) ) . element ( "<STR_LIT:boolean>" , Boolean . TRUE ) . element ( "<STR_LIT:string>" , "<STR_LIT:string>" ) ; values . put ( "<STR_LIT>" , values2 ) ; values3 = new JSONObject ( ) . element ( "<STR_LIT:int>" , Integer . valueOf ( "<STR_LIT:2>" ) ) . element ( "<STR_LIT:long>" , Long . valueOf ( "<STR_LIT:2>" ) ) . element ( "<STR_LIT:boolean>" , Boolean . FALSE ) . element ( "<STR_LIT:string>" , "<STR_LIT>" ) ; values . put ( "<STR_LIT>" , values3 ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectEqualsHashCodeCompareTo . class ) ; } public TestJSONObjectEqualsHashCodeCompareTo ( String name ) { super ( name ) ; } public void testCompareTo_different_size ( ) { assertEquals ( - <NUM_LIT:1> , values2 . compareTo ( strings ) ) ; assertEquals ( <NUM_LIT:1> , strings . compareTo ( values2 ) ) ; } public void testCompareTo_null ( ) { assertEquals ( - <NUM_LIT:1> , strings . compareTo ( null ) ) ; } public void testCompareTo_object ( ) { assertEquals ( - <NUM_LIT:1> , strings . compareTo ( new Object ( ) ) ) ; } public void testCompareTo_same_array ( ) { assertEquals ( <NUM_LIT:0> , strings . compareTo ( strings ) ) ; } public void testCompareTo_same_size_different_values ( ) { assertEquals ( - <NUM_LIT:1> , values2 . compareTo ( values3 ) ) ; } public void testCompareTo_same_size_similar_values ( ) { assertEquals ( <NUM_LIT:0> , strings . compareTo ( values1 ) ) ; } public void testEquals_different_key_same_size ( ) { JSONObject a = new JSONObject ( ) . element ( "<STR_LIT:key1>" , "<STR_LIT:string>" ) ; JSONObject b = new JSONObject ( ) . element ( "<STR_LIT>" , "<STR_LIT>" ) ; assertFalse ( a . equals ( b ) ) ; assertFalse ( b . equals ( a ) ) ; } public void testEquals_different_sizes ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_nullObject_other ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_nullObjects_different ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_other_nullObject ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_same ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_same_key_different_value ( ) { JSONObject a = new JSONObject ( ) . element ( "<STR_LIT:key>" , "<STR_LIT:string>" ) ; JSONObject b = new JSONObject ( ) . element ( "<STR_LIT:key>" , "<STR_LIT>" ) ; assertFalse ( a . equals ( b ) ) ; assertFalse ( b . equals ( a ) ) ; } public void testEquals_strings_values ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testEquals_to_null ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . equals ( null ) ) ; } public void testEquals_to_other ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . equals ( new Object ( ) ) ) ; } public void testEquals_values_strings ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . equals ( values . get ( "<STR_LIT>" ) ) ) ; } public void testHashCode_different_size ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_nullObject_other ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_nullObjects_different ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_other_nullObject ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_same ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_same_key_different_value ( ) { JSONObject a = new JSONObject ( ) . element ( "<STR_LIT:key>" , "<STR_LIT:string>" ) ; JSONObject b = new JSONObject ( ) . element ( "<STR_LIT:key>" , "<STR_LIT>" ) ; assertFalse ( a . hashCode ( ) == b . hashCode ( ) ) ; } public void testHashCode_strings_values ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } public void testHashCode_to_other ( ) { assertFalse ( values . get ( "<STR_LIT>" ) . hashCode ( ) == new Object ( ) . hashCode ( ) ) ; } public void testHashCode_values_strings ( ) { assertTrue ( values . get ( "<STR_LIT>" ) . hashCode ( ) == values . get ( "<STR_LIT>" ) . hashCode ( ) ) ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; public class TestJSONArrayStaticBuilders_Array_DynaBean extends AbstractJSONArrayStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayStaticBuilders_Array_DynaBean . class ) ; } public TestJSONArrayStaticBuilders_Array_DynaBean ( String name ) { super ( name ) ; } protected Object getSource ( ) { Map map = new HashMap ( ) ; String [ ] props = getProperties ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { map . put ( props [ i ] , PropertyConstants . getPropertyClass ( props [ i ] ) ) ; } map . put ( "<STR_LIT:class>" , Class . class ) ; map . put ( "<STR_LIT>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( map ) ; MorphDynaBean dynaBean = null ; try { dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { dynaBean . set ( props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } dynaBean . set ( "<STR_LIT:class>" , Object . class ) ; dynaBean . set ( "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return new Object [ ] { dynaBean } ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; public class TestJSONArrayEqualsHashCodeCompareTo extends TestCase { private static JSONArray strings ; private static Map values = new HashMap ( ) ; private static JSONArray values1 ; private static JSONArray values2 ; private static JSONArray values3 ; static { values . put ( "<STR_LIT>" , Integer . valueOf ( "<STR_LIT:1>" ) ) ; values . put ( "<STR_LIT>" , Integer . valueOf ( "<STR_LIT:2>" ) ) ; values . put ( "<STR_LIT>" , Long . valueOf ( "<STR_LIT:1>" ) ) ; values . put ( "<STR_LIT>" , Long . valueOf ( "<STR_LIT:2>" ) ) ; values . put ( "<STR_LIT>" , "<STR_LIT:1>" ) ; values . put ( "<STR_LIT>" , "<STR_LIT:2>" ) ; values . put ( "<STR_LIT>" , Boolean . TRUE ) ; values . put ( "<STR_LIT>" , Boolean . FALSE ) ; strings = new JSONArray ( ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" ) . element ( "<STR_LIT>" ) . element ( "<STR_LIT>" ) ; values . put ( "<STR_LIT>" , strings ) ; values1 = new JSONArray ( ) . element ( Integer . valueOf ( "<STR_LIT:1>" ) ) . element ( Long . valueOf ( "<STR_LIT:1>" ) ) . element ( Boolean . TRUE ) . element ( "<STR_LIT:string>" ) . element ( new JSONFunction ( "<STR_LIT>" ) ) . element ( JSONArray . fromObject ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } ) ) ; values . put ( "<STR_LIT>" , values1 ) ; values2 = new JSONArray ( ) . element ( Integer . valueOf ( "<STR_LIT:1>" ) ) . element ( Long . valueOf ( "<STR_LIT:1>" ) ) . element ( Boolean . TRUE ) . element ( "<STR_LIT:string>" ) ; values . put ( "<STR_LIT>" , values2 ) ; values3 = new JSONArray ( ) . element ( Integer . valueOf ( "<STR_LIT:2>" ) ) . element ( Long . valueOf ( "<STR_LIT:2>" ) ) . element ( Boolean . FALSE ) . element ( "<STR_LIT>" ) ; values . put ( "<STR_LIT>" , values3 ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayEqualsHashCodeCompareTo . class ) ; } public TestJSONArrayEqualsHashCodeCompareTo ( String name ) { super ( name ) ; } public void testCompareTo_different_size ( ) { assertEquals ( - <NUM_LIT:1> , values2 . compareTo ( strings ) ) ; assertEquals ( <NUM_LIT:1> , strings . compareTo ( values2 ) ) ; } public void testCompareTo_null ( ) { assertEquals ( - <NUM_LIT:1> , strings . compareTo ( null ) ) ; } public void testCompareTo_object ( ) { assertEquals ( - <NUM_LIT:1> , strings . compareTo ( new Object ( ) ) ) ; } public void testCompareTo_same_array ( ) { assertEquals ( <NUM_LIT:0> , strings . compareTo ( strings ) ) ; } public void testCompareTo_same_size_different_values ( ) { assertEquals ( - <NUM_LIT:1> , values2 . compareTo ( values3 ) ) ; } public void testCompareTo_same_size_similar_values ( ) { assertEquals ( <NUM_LIT:0> , strings . compareTo ( values1 ) ) ; } public void testEquals_different_elements_same_size ( ) { assertFalse ( values2 . equals ( values3 ) ) ; assertFalse ( values3 . equals ( values2 ) ) ; } public void testEquals_null ( ) { assertFalse ( strings . equals ( null ) ) ; } public void testEquals_object ( ) { assertFalse ( strings . equals ( new Object ( ) ) ) ; } public void testEquals_same_object ( ) { assertTrue ( strings . equals ( strings ) ) ; } public void testEquals_same_size_similar_values ( ) { assertTrue ( strings . equals ( values1 ) ) ; } public void testHashCode_different_elements_same_size ( ) { assertFalse ( values2 . hashCode ( ) == values3 . hashCode ( ) ) ; } } </s>
<s> package net . sf . json ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_ObjectBean . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_PrimitiveBean . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_DynaBean . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_JSONObject . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_JSONString . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_JSONTokener . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_Map . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectStaticBuilders_String . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayStaticBuilders_Array_DynaBean . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayStaticBuilders_Collection_DynaBean . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayStaticBuilders_JSONString . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayStaticBuilders_String . class ) ) ; suite . addTest ( new TestSuite ( TestJSONFunction . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArray . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObject . class ) ) ; suite . addTest ( new TestSuite ( TestJSONSerializer . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayAsJSON . class ) ) ; suite . addTest ( new TestSuite ( TestJSONNullAsJSON . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectWithProcessors . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectEqualsHashCodeCompareTo . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayEqualsHashCodeCompareTo . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectEvents . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayEvents . class ) ) ; suite . addTest ( new TestSuite ( TestJSONObjectAsMap . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayAsList . class ) ) ; suite . addTest ( new TestSuite ( TestUserSubmitted . class ) ) ; suite . addTest ( new TestSuite ( TestJSONArrayCollections . class ) ) ; return suite ; } } </s>
<s> package net . sf . json . sample ; public class AnnotatedBean { private String string1 ; @ JsonAnnotation private String string2 ; private String string3 ; public String getString1 ( ) { return string1 ; } public void setString1 ( String string ) { this . string1 = string ; } public String getString2 ( ) { return string2 ; } public void setString2 ( String string ) { this . string2 = string ; } @ JsonAnnotation public String getString3 ( ) { return string3 ; } public void setString3 ( String string ) { this . string3 = string ; } } </s>
<s> package net . sf . json . sample ; import java . util . Set ; import java . util . HashSet ; public class EnumBean { private JsonEnum jsonEnum ; private String string ; private Set < JsonEnum > enums = new HashSet < JsonEnum > ( ) ; public JsonEnum getJsonEnum ( ) { return jsonEnum ; } public String getString ( ) { return string ; } public Set < JsonEnum > getEnums ( ) { return enums ; } public void setJsonEnum ( JsonEnum jsonEnum ) { this . jsonEnum = jsonEnum ; } public void setString ( String string ) { this . string = string ; } public void setEnums ( Set < JsonEnum > enums ) { this . enums = enums ; } } </s>
<s> package net . sf . json . sample ; @ JsonAnnotation ( "<STR_LIT>" ) public class AnnotationBean { private String string ; public String getString ( ) { return string ; } public void setString ( String string ) { this . string = string ; } } </s>
<s> package net . sf . json . sample ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; @ Retention ( RetentionPolicy . RUNTIME ) public @ interface JsonAnnotation { String value ( ) default "<STR_LIT>" ; } </s>
<s> package net . sf . json . sample ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; public class GenericsBean { private List < GenericsInternalBean > genericsInternalBeanList ; private List noTypeList ; private ArrayList < String > stringArrayList ; private HashSet < String > stringHashSet ; private List < String > stringList ; private Set < String > stringSet ; public List < GenericsInternalBean > getGenericsInternalBeanList ( ) { return genericsInternalBeanList ; } public List getNoTypeList ( ) { return noTypeList ; } public ArrayList < String > getStringArrayList ( ) { return stringArrayList ; } public HashSet < String > getStringHashSet ( ) { return stringHashSet ; } public List < String > getStringList ( ) { return stringList ; } public Set < String > getStringSet ( ) { return stringSet ; } public void setGenericsInternalBeanList ( List < GenericsInternalBean > genericsInternalBeanList ) { this . genericsInternalBeanList = genericsInternalBeanList ; } public void setNoTypeList ( List noTypeList ) { this . noTypeList = noTypeList ; } public void setStringArrayList ( ArrayList < String > stringArrayList ) { this . stringArrayList = stringArrayList ; } public void setStringHashSet ( HashSet < String > stringHashSet ) { this . stringHashSet = stringHashSet ; } public void setStringList ( List < String > stringList ) { this . stringList = stringList ; } public void setStringSet ( Set < String > stringSet ) { this . stringSet = stringSet ; } public static class GenericsInternalBean { private String string ; public String getString ( ) { return string ; } public void setString ( String string ) { this . string = string ; } } } </s>
<s> package net . sf . json . sample ; public enum JsonEnum { ARRAY , OBJECT } </s>
<s> package net . sf . json ; import java . lang . annotation . Annotation ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . ezmorph . Morpher ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; import net . sf . json . sample . AnnotationBean ; import net . sf . json . sample . AnnotatedBean ; import net . sf . json . sample . EnumBean ; import net . sf . json . sample . JsonEnum ; import net . sf . json . sample . JsonAnnotation ; import net . sf . json . util . EnumMorpher ; import net . sf . json . util . JSONUtils ; public class TestJSONObjectJdk15 extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectJdk15 . class ) ; } public TestJSONObjectJdk15 ( String testName ) { super ( testName ) ; } public void testFromBean_AnnotationBean ( ) { AnnotationBean bean = new AnnotationBean ( ) ; Annotation [ ] annotations = bean . getClass ( ) . getAnnotations ( ) ; try { JSONObject . fromObject ( annotations [ <NUM_LIT:0> ] ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromBean_Enum ( ) { try { JSONObject . fromObject ( JsonEnum . OBJECT ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromBean_EnumBean ( ) { EnumBean bean = new EnumBean ( ) ; bean . setJsonEnum ( JsonEnum . OBJECT ) ; bean . setString ( "<STR_LIT:string>" ) ; JSONObject json = JSONObject . fromObject ( bean ) ; assertNotNull ( json ) ; assertEquals ( JsonEnum . OBJECT . toString ( ) , json . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:string>" , json . get ( "<STR_LIT:string>" ) ) ; } public void testFromObject_AnnotationBean ( ) { AnnotationBean bean = new AnnotationBean ( ) ; Annotation [ ] annotations = bean . getClass ( ) . getAnnotations ( ) ; try { JSONObject . fromObject ( annotations [ <NUM_LIT:0> ] ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromObject_DynaBean__Enum ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT>" , JsonEnum . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT>" , JsonEnum . OBJECT ) ; JSONObject json = JSONObject . fromObject ( dynaBean ) ; assertNotNull ( json ) ; assertEquals ( JsonEnum . OBJECT . toString ( ) , json . get ( "<STR_LIT>" ) ) ; } public void testFromObject_Enum ( ) { try { JSONObject . fromObject ( JsonEnum . OBJECT ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testFromObject_EnumBean ( ) { EnumBean bean = new EnumBean ( ) ; bean . setJsonEnum ( JsonEnum . OBJECT ) ; bean . setString ( "<STR_LIT:string>" ) ; JSONObject json = JSONObject . fromObject ( bean ) ; assertNotNull ( json ) ; assertEquals ( JsonEnum . OBJECT . toString ( ) , json . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:string>" , json . get ( "<STR_LIT:string>" ) ) ; } public void testFromObject_Map__Enum ( ) { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT>" , JsonEnum . OBJECT ) ; JSONObject json = JSONObject . fromObject ( properties ) ; assertNotNull ( json ) ; assertEquals ( JsonEnum . OBJECT . toString ( ) , json . get ( "<STR_LIT>" ) ) ; } public void testPut_Annotation ( ) { AnnotationBean bean = new AnnotationBean ( ) ; Annotation [ ] annotations = bean . getClass ( ) . getAnnotations ( ) ; try { JSONObject jsonObject = new JSONObject ( ) ; jsonObject . element ( "<STR_LIT>" , annotations [ <NUM_LIT:0> ] ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testPut_Enum ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , JsonEnum . OBJECT ) ; assertEquals ( JsonEnum . OBJECT . toString ( ) , json . get ( "<STR_LIT>" ) ) ; } public void testToBean_EnumBean ( ) { JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new EnumMorpher ( JsonEnum . class ) ) ; JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , "<STR_LIT>" ) ; EnumBean bean = ( EnumBean ) JSONObject . toBean ( json , EnumBean . class ) ; assertNotNull ( bean ) ; assertEquals ( bean . getJsonEnum ( ) , JsonEnum . OBJECT ) ; } public void testToBean_EnumBean_autoRegisterMorpher ( ) { JSONObject json = new JSONObject ( ) ; json . element ( "<STR_LIT>" , "<STR_LIT>" ) ; EnumBean bean = ( EnumBean ) JSONObject . toBean ( json , EnumBean . class ) ; assertNotNull ( bean ) ; assertEquals ( bean . getJsonEnum ( ) , JsonEnum . OBJECT ) ; } public void testFromObject_ignoreAnnotations ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . addIgnoreFieldAnnotation ( JsonAnnotation . class ) ; AnnotatedBean bean = new AnnotatedBean ( ) ; bean . setString1 ( "<STR_LIT>" ) ; bean . setString2 ( "<STR_LIT>" ) ; bean . setString3 ( "<STR_LIT>" ) ; JSONObject json = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( json ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; assertFalse ( json . has ( "<STR_LIT>" ) ) ; jsonConfig . setIgnoreTransientFields ( true ) ; json = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( json ) ; assertEquals ( "<STR_LIT>" , json . get ( "<STR_LIT>" ) ) ; assertFalse ( json . has ( "<STR_LIT>" ) ) ; assertFalse ( json . has ( "<STR_LIT>" ) ) ; } protected void setUp ( ) throws Exception { Morpher morpher = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( JsonEnum . class ) ; JSONUtils . getMorpherRegistry ( ) . deregisterMorpher ( morpher ) ; } } </s>
<s> package net . sf . json ; import java . beans . PropertyDescriptor ; import java . util . ArrayList ; import java . util . Collection ; import java . util . HashSet ; import junit . framework . TestCase ; import net . sf . json . sample . GenericsBean ; import net . sf . json . sample . GenericsBean . GenericsInternalBean ; import org . apache . commons . beanutils . PropertyUtils ; public class TestJSONArrayCollection extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayCollection . class ) ; } public TestJSONArrayCollection ( String testName ) { super ( testName ) ; } public void testNOOP ( ) { } } </s>
<s> package net . sf . json ; import java . lang . annotation . Annotation ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import net . sf . json . sample . AnnotationBean ; import net . sf . json . sample . JsonEnum ; public class TestJSONArrayJdk15 extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayJdk15 . class ) ; } public TestJSONArrayJdk15 ( String testName ) { super ( testName ) ; } public void testConstructor_Annotation ( ) { AnnotationBean bean = new AnnotationBean ( ) ; Annotation [ ] annotations = bean . getClass ( ) . getAnnotations ( ) ; try { JSONArray . fromObject ( annotations [ <NUM_LIT:0> ] ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testConstructor_Collection ( ) { List l = new ArrayList ( ) ; l . add ( Boolean . TRUE ) ; l . add ( new Integer ( <NUM_LIT:1> ) ) ; l . add ( "<STR_LIT:string>" ) ; l . add ( Object . class ) ; l . add ( JsonEnum . ARRAY ) ; testJSONArray ( l , "<STR_LIT>" ) ; } public void testConstructor_Enum ( ) { testJSONArray ( JsonEnum . ARRAY , "<STR_LIT>" ) ; } public void testConstructor_Object_Array_Enum ( ) { JSONArray expected = JSONArray . fromObject ( "<STR_LIT>" ) ; JSONArray actual = JSONArray . fromObject ( new JsonEnum [ ] { JsonEnum . ARRAY , JsonEnum . OBJECT } ) ; Assertions . assertEquals ( expected , actual ) ; } public void testFromObject_Enum ( ) { JSONArray actual = JSONArray . fromObject ( JsonEnum . ARRAY ) ; JSONArray expected = new JSONArray ( ) . element ( "<STR_LIT>" ) ; Assertions . assertEquals ( expected , actual ) ; } public void testPut_Enum ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( JsonEnum . ARRAY ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertEquals ( "<STR_LIT>" , jsonArray . get ( <NUM_LIT:0> ) ) ; } public void testPut_Enum_2 ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( ( JsonEnum ) null ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; } public void testPut_index_0_Annotation ( ) { AnnotationBean bean = new AnnotationBean ( ) ; Annotation [ ] annotations = bean . getClass ( ) . getAnnotations ( ) ; try { JSONArray array = JSONArray . fromObject ( "<STR_LIT>" ) ; array . element ( <NUM_LIT:0> , annotations [ <NUM_LIT:0> ] ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { } } public void testPut_index_0_Enum ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . element ( <NUM_LIT:0> , JsonEnum . ARRAY ) ; assertEquals ( "<STR_LIT>" , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:1> ) ) ; } public void testPut_index_0_Enum_2 ( ) { JSONArray jsonArray = JSONArray . fromObject ( "<STR_LIT>" ) ; jsonArray . element ( <NUM_LIT:0> , ( JsonEnum ) null ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:1> ) ) ; } public void testPut_index_1_Enum ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , JsonEnum . ARRAY ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , jsonArray . get ( <NUM_LIT:1> ) ) ; } public void testPut_index_1_Enum_2 ( ) { JSONArray jsonArray = new JSONArray ( ) ; jsonArray . element ( <NUM_LIT:1> , ( JsonEnum ) null ) ; assertEquals ( <NUM_LIT:2> , jsonArray . size ( ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( JSONNull . getInstance ( ) , jsonArray . get ( <NUM_LIT:1> ) ) ; } private void testJSONArray ( Object array , String expected ) { try { JSONArray jsonArray = JSONArray . fromObject ( array ) ; assertEquals ( expected , jsonArray . toString ( ) ) ; } catch ( JSONException jsone ) { fail ( jsone . getMessage ( ) ) ; } } } </s>
<s> package net . sf . json ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import junit . framework . TestCase ; import net . sf . json . sample . GenericsBean ; import net . sf . json . sample . GenericsBean . GenericsInternalBean ; public class TestGenerics extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestGenerics . class ) ; } public TestGenerics ( String testName ) { super ( testName ) ; } public void testNOOP ( ) { } public static class OnlyListBean { private List < String > stringList ; public List < String > getStringList ( ) { return stringList ; } public void setStringList ( List < String > stringList ) { this . stringList = stringList ; } } } </s>
<s> package net . sf . json . bugs ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; public class TestBug2843623 extends TestCase { public void testSample ( ) { Container orig = new Container ( ) ; List < String > strings = new ArrayList < String > ( ) ; strings . add ( "<STR_LIT:one>" ) ; strings . add ( "<STR_LIT:two>" ) ; strings . add ( "<STR_LIT>" ) ; orig . setMyList ( strings ) ; JSONObject jobj = JSONObject . fromObject ( orig ) ; Container root = new Container ( ) ; Container res = ( Container ) JSONObject . toBean ( jobj , root , new JsonConfig ( ) ) ; assertTrue ( res . getMyList ( ) . size ( ) > <NUM_LIT:0> ) ; assertTrue ( root . getMyList ( ) . size ( ) > <NUM_LIT:0> ) ; } public static class Container { private List < String > myList = new ArrayList < String > ( ) ; public List < String > getMyList ( ) { return myList ; } public void setMyList ( List < String > strings ) { this . myList . addAll ( strings ) ; } } } </s>
<s> package net . sf . json ; import java . beans . PropertyDescriptor ; import java . io . IOException ; import java . io . Writer ; import java . lang . annotation . Annotation ; import java . lang . reflect . Array ; import java . lang . reflect . Method ; import java . lang . reflect . ParameterizedType ; import java . lang . reflect . Type ; import java . util . ArrayList ; import java . util . Collection ; import java . util . ConcurrentModificationException ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import java . util . ListIterator ; import java . util . Map ; import java . util . NoSuchElementException ; import java . util . Set ; import net . sf . ezmorph . Morpher ; import net . sf . ezmorph . object . IdentityObjectMorpher ; import net . sf . json . processors . JsonValueProcessor ; import net . sf . json . processors . JsonVerifier ; import net . sf . json . util . JSONTokener ; import net . sf . json . util . JSONUtils ; import org . apache . commons . lang . StringUtils ; public final class JSONArray extends AbstractJSON implements JSON , List < Object > , Comparable { public static JSONArray fromObject ( Object object ) { return fromObject ( object , new JsonConfig ( ) ) ; } public static JSONArray fromObject ( Object object , JsonConfig jsonConfig ) { if ( object instanceof JSONString ) { return _fromJSONString ( ( JSONString ) object , jsonConfig ) ; } else if ( object instanceof JSONArray ) { return _fromJSONArray ( ( JSONArray ) object , jsonConfig ) ; } else if ( object instanceof Collection ) { return _fromCollection ( ( Collection ) object , jsonConfig ) ; } else if ( object instanceof JSONTokener ) { return _fromJSONTokener ( ( JSONTokener ) object , jsonConfig ) ; } else if ( object instanceof String ) { return _fromString ( ( String ) object , jsonConfig ) ; } else if ( object != null && object . getClass ( ) . isArray ( ) ) { Class type = object . getClass ( ) . getComponentType ( ) ; if ( ! type . isPrimitive ( ) ) { return _fromArray ( ( Object [ ] ) object , jsonConfig ) ; } else { if ( type == Boolean . TYPE ) { return _fromArray ( ( boolean [ ] ) object , jsonConfig ) ; } else if ( type == Byte . TYPE ) { return _fromArray ( ( byte [ ] ) object , jsonConfig ) ; } else if ( type == Short . TYPE ) { return _fromArray ( ( short [ ] ) object , jsonConfig ) ; } else if ( type == Integer . TYPE ) { return _fromArray ( ( int [ ] ) object , jsonConfig ) ; } else if ( type == Long . TYPE ) { return _fromArray ( ( long [ ] ) object , jsonConfig ) ; } else if ( type == Float . TYPE ) { return _fromArray ( ( float [ ] ) object , jsonConfig ) ; } else if ( type == Double . TYPE ) { return _fromArray ( ( double [ ] ) object , jsonConfig ) ; } else if ( type == Character . TYPE ) { return _fromArray ( ( char [ ] ) object , jsonConfig ) ; } else { throw new JSONException ( "<STR_LIT>" ) ; } } } else if ( JSONUtils . isBoolean ( object ) || JSONUtils . isFunction ( object ) || JSONUtils . isNumber ( object ) || JSONUtils . isNull ( object ) || JSONUtils . isString ( object ) || object instanceof JSON ) { fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) . element ( object , jsonConfig ) ; fireElementAddedEvent ( <NUM_LIT:0> , jsonArray . get ( <NUM_LIT:0> ) , jsonConfig ) ; fireArrayStartEvent ( jsonConfig ) ; return jsonArray ; } else if ( object instanceof Enum ) { return _fromArray ( ( Enum ) object , jsonConfig ) ; } else if ( object instanceof Annotation || ( object != null && object . getClass ( ) . isAnnotation ( ) ) ) { throw new JSONException ( "<STR_LIT>" ) ; } else if ( JSONUtils . isObject ( object ) ) { fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) . element ( JSONObject . fromObject ( object , jsonConfig ) ) ; fireElementAddedEvent ( <NUM_LIT:0> , jsonArray . get ( <NUM_LIT:0> ) , jsonConfig ) ; fireArrayStartEvent ( jsonConfig ) ; return jsonArray ; } else { throw new JSONException ( "<STR_LIT>" ) ; } } public static Class [ ] getCollectionType ( PropertyDescriptor pd , boolean useGetter ) throws JSONException { Type type ; if ( useGetter ) { Method m = pd . getReadMethod ( ) ; type = m . getGenericReturnType ( ) ; } else { Method m = pd . getWriteMethod ( ) ; Type [ ] gpts = m . getGenericParameterTypes ( ) ; if ( <NUM_LIT:1> != gpts . length ) { throw new JSONException ( "<STR_LIT>" + m + "<STR_LIT>" ) ; } type = gpts [ <NUM_LIT:0> ] ; } if ( ! ( type instanceof ParameterizedType ) ) { return null ; } ParameterizedType pType = ( ParameterizedType ) type ; Type [ ] actualTypes = pType . getActualTypeArguments ( ) ; Class [ ] ret = new Class [ actualTypes . length ] ; for ( int i = <NUM_LIT:0> ; i < ret . length ; i ++ ) { ret [ i ] = ( Class ) actualTypes [ i ] ; } return ret ; } public static int [ ] getDimensions ( JSONArray jsonArray ) { if ( jsonArray == null || jsonArray . isEmpty ( ) ) { return new int [ ] { <NUM_LIT:0> } ; } List dims = new ArrayList ( ) ; processArrayDimensions ( jsonArray , dims , <NUM_LIT:0> ) ; int [ ] dimensions = new int [ dims . size ( ) ] ; int j = <NUM_LIT:0> ; for ( Iterator i = dims . iterator ( ) ; i . hasNext ( ) ; ) { dimensions [ j ++ ] = ( ( Integer ) i . next ( ) ) . intValue ( ) ; } return dimensions ; } public static Object toArray ( JSONArray jsonArray ) { return toArray ( jsonArray , new JsonConfig ( ) ) ; } public static Object toArray ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toArray ( jsonArray , jsonConfig ) ; } public static Object toArray ( JSONArray jsonArray , Class objectClass , Map classMap ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; jsonConfig . setClassMap ( classMap ) ; return toArray ( jsonArray , jsonConfig ) ; } public static Object toArray ( JSONArray jsonArray , JsonConfig jsonConfig ) { Class objectClass = jsonConfig . getRootClass ( ) ; Map classMap = jsonConfig . getClassMap ( ) ; if ( jsonArray . size ( ) == <NUM_LIT:0> ) { return Array . newInstance ( objectClass == null ? Object . class : objectClass , <NUM_LIT:0> ) ; } int [ ] dimensions = JSONArray . getDimensions ( jsonArray ) ; Object array = Array . newInstance ( objectClass == null ? Object . class : objectClass , dimensions ) ; int size = jsonArray . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Object value = jsonArray . get ( i ) ; if ( JSONUtils . isNull ( value ) ) { Array . set ( array , i , null ) ; } else { Class type = value . getClass ( ) ; if ( JSONArray . class . isAssignableFrom ( type ) ) { Array . set ( array , i , toArray ( ( JSONArray ) value , objectClass , classMap ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( objectClass != null && ! objectClass . isAssignableFrom ( type ) ) { value = JSONUtils . getMorpherRegistry ( ) . morph ( objectClass , value ) ; } Array . set ( array , i , value ) ; } else if ( JSONUtils . isNumber ( type ) ) { if ( objectClass != null && ( Byte . class . isAssignableFrom ( objectClass ) || Byte . TYPE . isAssignableFrom ( objectClass ) ) ) { Array . set ( array , i , Byte . valueOf ( String . valueOf ( value ) ) ) ; } else if ( objectClass != null && ( Short . class . isAssignableFrom ( objectClass ) || Short . TYPE . isAssignableFrom ( objectClass ) ) ) { Array . set ( array , i , Short . valueOf ( String . valueOf ( value ) ) ) ; } else { Array . set ( array , i , value ) ; } } else { if ( objectClass != null ) { JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( objectClass ) ; jsc . setClassMap ( classMap ) ; Array . set ( array , i , JSONObject . toBean ( ( JSONObject ) value , jsc ) ) ; } else { Array . set ( array , i , JSONObject . toBean ( ( JSONObject ) value ) ) ; } } } } return array ; } public static Object toArray ( JSONArray jsonArray , Object root , JsonConfig jsonConfig ) { Class objectClass = root . getClass ( ) ; if ( jsonArray . size ( ) == <NUM_LIT:0> ) { return Array . newInstance ( objectClass , <NUM_LIT:0> ) ; } int [ ] dimensions = JSONArray . getDimensions ( jsonArray ) ; Object array = Array . newInstance ( objectClass == null ? Object . class : objectClass , dimensions ) ; int size = jsonArray . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Object value = jsonArray . get ( i ) ; if ( JSONUtils . isNull ( value ) ) { Array . set ( array , i , null ) ; } else { Class type = value . getClass ( ) ; if ( JSONArray . class . isAssignableFrom ( type ) ) { Array . set ( array , i , toArray ( ( JSONArray ) value , root , jsonConfig ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || JSONUtils . isNumber ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( objectClass != null && ! objectClass . isAssignableFrom ( type ) ) { value = JSONUtils . getMorpherRegistry ( ) . morph ( objectClass , value ) ; } Array . set ( array , i , value ) ; } else { try { Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( root . getClass ( ) , null ) ; Array . set ( array , i , JSONObject . toBean ( ( JSONObject ) value , newRoot , jsonConfig ) ) ; } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( e ) ; } } } } return array ; } public static Collection toCollection ( JSONArray jsonArray ) { return toCollection ( jsonArray , new JsonConfig ( ) ) ; } public static Collection toCollection ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toCollection ( jsonArray , jsonConfig ) ; } public static Collection toCollection ( JSONArray jsonArray , JsonConfig jsonConfig ) { Collection collection = null ; Class collectionType = jsonConfig . getCollectionType ( ) ; if ( collectionType . isInterface ( ) ) { if ( collectionType . equals ( List . class ) ) { collection = new ArrayList ( ) ; } else if ( collectionType . equals ( Set . class ) ) { collection = new HashSet ( ) ; } else { throw new JSONException ( "<STR_LIT>" + collectionType ) ; } } else { try { collection = ( Collection ) collectionType . newInstance ( ) ; } catch ( InstantiationException e ) { throw new JSONException ( e ) ; } catch ( IllegalAccessException e ) { throw new JSONException ( e ) ; } } Class objectClass = jsonConfig . getRootClass ( ) ; Map classMap = jsonConfig . getClassMap ( ) ; int size = jsonArray . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Object value = jsonArray . get ( i ) ; if ( JSONUtils . isNull ( value ) ) { collection . add ( null ) ; } else { Class type = value . getClass ( ) ; if ( JSONArray . class . isAssignableFrom ( value . getClass ( ) ) ) { collection . add ( toCollection ( ( JSONArray ) value , jsonConfig ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || JSONUtils . isNumber ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( objectClass != null && ! objectClass . isAssignableFrom ( type ) ) { value = JSONUtils . getMorpherRegistry ( ) . morph ( objectClass , value ) ; } collection . add ( value ) ; } else { if ( objectClass != null ) { JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( objectClass ) ; jsc . setClassMap ( classMap ) ; collection . add ( JSONObject . toBean ( ( JSONObject ) value , jsc ) ) ; } else { collection . add ( JSONObject . toBean ( ( JSONObject ) value ) ) ; } } } } return collection ; } public static List toList ( JSONArray jsonArray ) { return toList ( jsonArray , new JsonConfig ( ) ) ; } public static List toList ( JSONArray jsonArray , Class objectClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; return toList ( jsonArray , jsonConfig ) ; } public static List toList ( JSONArray jsonArray , Class objectClass , Map classMap ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( objectClass ) ; jsonConfig . setClassMap ( classMap ) ; return toList ( jsonArray , jsonConfig ) ; } public static List toList ( JSONArray jsonArray , JsonConfig jsonConfig ) { if ( jsonArray . size ( ) == <NUM_LIT:0> ) { return new ArrayList ( ) ; } Class objectClass = jsonConfig . getRootClass ( ) ; Map classMap = jsonConfig . getClassMap ( ) ; List list = new ArrayList ( ) ; int size = jsonArray . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Object value = jsonArray . get ( i ) ; if ( JSONUtils . isNull ( value ) ) { list . add ( null ) ; } else { Class type = value . getClass ( ) ; if ( JSONArray . class . isAssignableFrom ( type ) ) { list . add ( toList ( ( JSONArray ) value , objectClass , classMap ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || JSONUtils . isNumber ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( objectClass != null && ! objectClass . isAssignableFrom ( type ) ) { value = JSONUtils . getMorpherRegistry ( ) . morph ( objectClass , value ) ; } list . add ( value ) ; } else { if ( objectClass != null ) { JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( objectClass ) ; jsc . setClassMap ( classMap ) ; list . add ( JSONObject . toBean ( ( JSONObject ) value , jsc ) ) ; } else { list . add ( JSONObject . toBean ( ( JSONObject ) value ) ) ; } } } } return list ; } public static List toList ( JSONArray jsonArray , Object root , JsonConfig jsonConfig ) { if ( jsonArray . size ( ) == <NUM_LIT:0> || root == null ) { return new ArrayList ( ) ; } List list = new ArrayList ( ) ; int size = jsonArray . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Object value = jsonArray . get ( i ) ; if ( JSONUtils . isNull ( value ) ) { list . add ( null ) ; } else { Class type = value . getClass ( ) ; if ( JSONArray . class . isAssignableFrom ( type ) ) { list . add ( toList ( ( JSONArray ) value , root , jsonConfig ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || JSONUtils . isNumber ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { list . add ( value ) ; } else { try { Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( root . getClass ( ) , null ) ; list . add ( JSONObject . toBean ( ( JSONObject ) value , newRoot , jsonConfig ) ) ; } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( e ) ; } } } } return list ; } private static JSONArray _fromArray ( boolean [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Boolean b = array [ i ] ? Boolean . TRUE : Boolean . FALSE ; jsonArray . addValue ( b , jsonConfig ) ; fireElementAddedEvent ( i , b , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( byte [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Number n = JSONUtils . transformNumber ( new Byte ( array [ i ] ) ) ; jsonArray . addValue ( n , jsonConfig ) ; fireElementAddedEvent ( i , n , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( char [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Character c = new Character ( array [ i ] ) ; jsonArray . addValue ( c , jsonConfig ) ; fireElementAddedEvent ( i , c , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( double [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; try { for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Double d = array [ i ] ; JSONUtils . testValidity ( d ) ; jsonArray . addValue ( d , jsonConfig ) ; fireElementAddedEvent ( i , d , jsonConfig ) ; } } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( Enum e , JsonConfig jsonConfig ) { if ( ! addInstance ( e ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( e ) ; } catch ( JSONException jsone ) { removeInstance ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException re ) { removeInstance ( e ) ; JSONException jsone = new JSONException ( re ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; if ( e != null ) { jsonArray . addValue ( e , jsonConfig ) ; fireElementAddedEvent ( <NUM_LIT:0> , jsonArray . get ( <NUM_LIT:0> ) , jsonConfig ) ; } else { JSONException jsone = new JSONException ( "<STR_LIT>" ) ; removeInstance ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( e ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( float [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; try { for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Float f = array [ i ] ; JSONUtils . testValidity ( f ) ; jsonArray . addValue ( f , jsonConfig ) ; fireElementAddedEvent ( i , f , jsonConfig ) ; } } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( int [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Number n = new Integer ( array [ i ] ) ; jsonArray . addValue ( n , jsonConfig ) ; fireElementAddedEvent ( i , n , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( long [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Number n = JSONUtils . transformNumber ( new Long ( array [ i ] ) ) ; jsonArray . addValue ( n , jsonConfig ) ; fireElementAddedEvent ( i , n , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( Object [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; try { for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Object element = array [ i ] ; jsonArray . addValue ( element , jsonConfig ) ; fireElementAddedEvent ( i , jsonArray . get ( i ) , jsonConfig ) ; } } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromArray ( short [ ] array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { Number n = JSONUtils . transformNumber ( new Short ( array [ i ] ) ) ; jsonArray . addValue ( n , jsonConfig ) ; fireElementAddedEvent ( i , n , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromCollection ( Collection collection , JsonConfig jsonConfig ) { if ( ! addInstance ( collection ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( collection ) ; } catch ( JSONException jsone ) { removeInstance ( collection ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( collection ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; try { int i = <NUM_LIT:0> ; for ( Iterator elements = collection . iterator ( ) ; elements . hasNext ( ) ; ) { Object element = elements . next ( ) ; jsonArray . addValue ( element , jsonConfig ) ; fireElementAddedEvent ( i , jsonArray . get ( i ++ ) , jsonConfig ) ; } } catch ( JSONException jsone ) { removeInstance ( collection ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( collection ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( collection ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromJSONArray ( JSONArray array , JsonConfig jsonConfig ) { if ( ! addInstance ( array ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsArray ( array ) ; } catch ( JSONException jsone ) { removeInstance ( array ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( array ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireArrayStartEvent ( jsonConfig ) ; JSONArray jsonArray = new JSONArray ( ) ; int index = <NUM_LIT:0> ; for ( Iterator elements = array . iterator ( ) ; elements . hasNext ( ) ; ) { Object element = elements . next ( ) ; jsonArray . addValue ( element , jsonConfig ) ; fireElementAddedEvent ( index ++ , element , jsonConfig ) ; } removeInstance ( array ) ; fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } private static JSONArray _fromJSONString ( JSONString string , JsonConfig jsonConfig ) { return _fromJSONTokener ( new JSONTokener ( string . toJSONString ( ) ) , jsonConfig ) ; } private static JSONArray _fromJSONTokener ( JSONTokener tokener , JsonConfig jsonConfig ) { JSONArray jsonArray = new JSONArray ( ) ; int index = <NUM_LIT:0> ; try { if ( tokener . nextClean ( ) != '<CHAR_LIT:[>' ) { throw tokener . syntaxError ( "<STR_LIT>" ) ; } fireArrayStartEvent ( jsonConfig ) ; if ( tokener . nextClean ( ) == '<CHAR_LIT:]>' ) { fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } tokener . back ( ) ; for ( ; ; ) { if ( tokener . nextClean ( ) == '<CHAR_LIT:U+002C>' ) { tokener . back ( ) ; jsonArray . elements . add ( JSONNull . getInstance ( ) ) ; fireElementAddedEvent ( index , jsonArray . get ( index ++ ) , jsonConfig ) ; } else { tokener . back ( ) ; Object v = tokener . nextValue ( jsonConfig ) ; if ( ! JSONUtils . isFunctionHeader ( v ) ) { if ( v instanceof String && JSONUtils . mayBeJSON ( ( String ) v ) ) { jsonArray . addValue ( JSONUtils . DOUBLE_QUOTE + v + JSONUtils . DOUBLE_QUOTE , jsonConfig ) ; } else { jsonArray . addValue ( v , jsonConfig ) ; } fireElementAddedEvent ( index , jsonArray . get ( index ++ ) , jsonConfig ) ; } else { String params = JSONUtils . getFunctionParams ( ( String ) v ) ; int i = <NUM_LIT:0> ; StringBuffer sb = new StringBuffer ( ) ; for ( ; ; ) { char ch = tokener . next ( ) ; if ( ch == <NUM_LIT:0> ) { break ; } if ( ch == '<CHAR_LIT>' ) { i ++ ; } if ( ch == '<CHAR_LIT:}>' ) { i -- ; } sb . append ( ch ) ; if ( i == <NUM_LIT:0> ) { break ; } } if ( i != <NUM_LIT:0> ) { throw tokener . syntaxError ( "<STR_LIT>" + v ) ; } String text = sb . toString ( ) ; text = text . substring ( <NUM_LIT:1> , text . length ( ) - <NUM_LIT:1> ) . trim ( ) ; jsonArray . addValue ( new JSONFunction ( ( params != null ) ? StringUtils . split ( params , "<STR_LIT:U+002C>" ) : null , text ) , jsonConfig ) ; fireElementAddedEvent ( index , jsonArray . get ( index ++ ) , jsonConfig ) ; } } switch ( tokener . nextClean ( ) ) { case '<CHAR_LIT:;>' : case '<CHAR_LIT:U+002C>' : if ( tokener . nextClean ( ) == '<CHAR_LIT:]>' ) { fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; } tokener . back ( ) ; break ; case '<CHAR_LIT:]>' : fireArrayEndEvent ( jsonConfig ) ; return jsonArray ; default : throw tokener . syntaxError ( "<STR_LIT>" ) ; } } } catch ( JSONException jsone ) { fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } private static JSONArray _fromString ( String string , JsonConfig jsonConfig ) { return _fromJSONTokener ( new JSONTokener ( string ) , jsonConfig ) ; } private static void processArrayDimensions ( JSONArray jsonArray , List dims , int index ) { if ( dims . size ( ) <= index ) { dims . add ( jsonArray . size ( ) ) ; } else { int i = ( ( Integer ) dims . get ( index ) ) . intValue ( ) ; if ( jsonArray . size ( ) > i ) { dims . set ( index , jsonArray . size ( ) ) ; } } for ( Iterator i = jsonArray . iterator ( ) ; i . hasNext ( ) ; ) { Object item = i . next ( ) ; if ( item instanceof JSONArray ) { processArrayDimensions ( ( JSONArray ) item , dims , index + <NUM_LIT:1> ) ; } } } private List < Object > elements ; private boolean expandElements ; public JSONArray ( ) { this . elements = new ArrayList < Object > ( ) ; } public void add ( int index , Object value ) { add ( index , value , new JsonConfig ( ) ) ; } public void add ( int index , Object value , JsonConfig jsonConfig ) { this . elements . add ( index , processValue ( value , jsonConfig ) ) ; } public boolean add ( Object value ) { return add ( value , new JsonConfig ( ) ) ; } public boolean add ( Object value , JsonConfig jsonConfig ) { element ( value , jsonConfig ) ; return true ; } public boolean addAll ( Collection collection ) { return addAll ( collection , new JsonConfig ( ) ) ; } public boolean addAll ( Collection collection , JsonConfig jsonConfig ) { if ( collection == null || collection . size ( ) == <NUM_LIT:0> ) { return false ; } for ( Object a : collection ) { element ( a , jsonConfig ) ; } return true ; } public boolean addAll ( int index , Collection collection ) { return addAll ( index , collection , new JsonConfig ( ) ) ; } public boolean addAll ( int index , Collection collection , JsonConfig jsonConfig ) { if ( collection == null || collection . size ( ) == <NUM_LIT:0> ) { return false ; } int offset = <NUM_LIT:0> ; for ( Object a : collection ) { this . elements . add ( index + ( offset ++ ) , processValue ( a , jsonConfig ) ) ; } return true ; } public void clear ( ) { elements . clear ( ) ; } public int compareTo ( Object obj ) { if ( obj != null && ( obj instanceof JSONArray ) ) { JSONArray other = ( JSONArray ) obj ; int size1 = size ( ) ; int size2 = other . size ( ) ; if ( size1 < size2 ) { return - <NUM_LIT:1> ; } else if ( size1 > size2 ) { return <NUM_LIT:1> ; } else if ( this . equals ( other ) ) { return <NUM_LIT:0> ; } } return - <NUM_LIT:1> ; } public boolean contains ( Object o ) { return contains ( o , new JsonConfig ( ) ) ; } public boolean contains ( Object o , JsonConfig jsonConfig ) { return elements . contains ( processValue ( o , jsonConfig ) ) ; } public boolean containsAll ( Collection collection ) { return containsAll ( collection , new JsonConfig ( ) ) ; } public boolean containsAll ( Collection collection , JsonConfig jsonConfig ) { return elements . containsAll ( fromObject ( collection , jsonConfig ) ) ; } public JSONArray discard ( int index ) { elements . remove ( index ) ; return this ; } public JSONArray discard ( Object o ) { elements . remove ( o ) ; return this ; } public JSONArray element ( boolean value ) { return element ( value ? Boolean . TRUE : Boolean . FALSE ) ; } public JSONArray element ( Collection value ) { return element ( value , new JsonConfig ( ) ) ; } public JSONArray element ( Collection value , JsonConfig jsonConfig ) { if ( value instanceof JSONArray ) { elements . add ( value ) ; return this ; } else { return element ( _fromCollection ( value , jsonConfig ) ) ; } } public JSONArray element ( double value ) { Double d = value ; JSONUtils . testValidity ( d ) ; return element ( d ) ; } public JSONArray element ( int value ) { return element ( new Integer ( value ) ) ; } public JSONArray element ( int index , boolean value ) { return element ( index , value ? Boolean . TRUE : Boolean . FALSE ) ; } public JSONArray element ( int index , Collection value ) { return element ( index , value , new JsonConfig ( ) ) ; } public JSONArray element ( int index , Collection value , JsonConfig jsonConfig ) { if ( value instanceof JSONArray ) { if ( index < <NUM_LIT:0> ) { throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } if ( index < size ( ) ) { elements . set ( index , value ) ; } else { while ( index != size ( ) ) { element ( JSONNull . getInstance ( ) ) ; } element ( value , jsonConfig ) ; } return this ; } else { return element ( index , _fromCollection ( value , jsonConfig ) ) ; } } public JSONArray element ( int index , double value ) { return element ( index , new Double ( value ) ) ; } public JSONArray element ( int index , int value ) { return element ( index , new Integer ( value ) ) ; } public JSONArray element ( int index , long value ) { return element ( index , new Long ( value ) ) ; } public JSONArray element ( int index , Map value ) { return element ( index , value , new JsonConfig ( ) ) ; } public JSONArray element ( int index , Map value , JsonConfig jsonConfig ) { if ( value instanceof JSONObject ) { if ( index < <NUM_LIT:0> ) { throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } if ( index < size ( ) ) { elements . set ( index , value ) ; } else { while ( index != size ( ) ) { element ( JSONNull . getInstance ( ) ) ; } element ( value , jsonConfig ) ; } return this ; } else { return element ( index , JSONObject . fromObject ( value , jsonConfig ) ) ; } } public JSONArray element ( int index , Object value ) { return element ( index , value , new JsonConfig ( ) ) ; } public JSONArray element ( int index , Object value , JsonConfig jsonConfig ) { JSONUtils . testValidity ( value ) ; if ( index < <NUM_LIT:0> ) { throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } if ( index < size ( ) ) { this . elements . set ( index , processValue ( value , jsonConfig ) ) ; } else { while ( index != size ( ) ) { element ( JSONNull . getInstance ( ) ) ; } element ( value , jsonConfig ) ; } return this ; } public JSONArray element ( int index , String value ) { return element ( index , value , new JsonConfig ( ) ) ; } public JSONArray element ( int index , String value , JsonConfig jsonConfig ) { if ( index < <NUM_LIT:0> ) { throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } if ( index < size ( ) ) { if ( value == null ) { this . elements . set ( index , "<STR_LIT>" ) ; } else if ( JSONUtils . mayBeJSON ( value ) ) { try { this . elements . set ( index , JSONSerializer . toJSON ( value , jsonConfig ) ) ; } catch ( JSONException jsone ) { this . elements . set ( index , JSONUtils . stripQuotes ( value ) ) ; } } else { this . elements . set ( index , JSONUtils . stripQuotes ( value ) ) ; } } else { while ( index != size ( ) ) { element ( JSONNull . getInstance ( ) ) ; } element ( value , jsonConfig ) ; } return this ; } public JSONArray element ( JSONNull value ) { this . elements . add ( value ) ; return this ; } public JSONArray element ( JSONObject value ) { this . elements . add ( value ) ; return this ; } public JSONArray element ( long value ) { return element ( JSONUtils . transformNumber ( value ) ) ; } public JSONArray element ( Map value ) { return element ( value , new JsonConfig ( ) ) ; } public JSONArray element ( Map value , JsonConfig jsonConfig ) { if ( value instanceof JSONObject ) { elements . add ( value ) ; return this ; } else { return element ( JSONObject . fromObject ( value , jsonConfig ) ) ; } } public JSONArray element ( Object value ) { return element ( value , new JsonConfig ( ) ) ; } public JSONArray element ( Object value , JsonConfig jsonConfig ) { return addValue ( value , jsonConfig ) ; } public JSONArray element ( String value ) { return element ( value , new JsonConfig ( ) ) ; } public JSONArray element ( String value , JsonConfig jsonConfig ) { if ( value == null ) { this . elements . add ( "<STR_LIT>" ) ; } else if ( JSONUtils . hasQuotes ( value ) ) { this . elements . add ( value ) ; } else if ( JSONNull . getInstance ( ) . equals ( value ) ) { this . elements . add ( JSONNull . getInstance ( ) ) ; } else if ( JSONUtils . isJsonKeyword ( value , jsonConfig ) ) { if ( jsonConfig . isJavascriptCompliant ( ) && "<STR_LIT>" . equals ( value ) ) { this . elements . add ( JSONNull . getInstance ( ) ) ; } else { this . elements . add ( value ) ; } } else if ( JSONUtils . mayBeJSON ( value ) ) { try { this . elements . add ( JSONSerializer . toJSON ( value , jsonConfig ) ) ; } catch ( JSONException jsone ) { this . elements . add ( value ) ; } } else { this . elements . add ( value ) ; } return this ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! ( obj instanceof JSONArray ) ) { return false ; } JSONArray other = ( JSONArray ) obj ; if ( other . size ( ) != size ( ) ) { return false ; } int max = size ( ) ; for ( int i = <NUM_LIT:0> ; i < max ; i ++ ) { Object o1 = get ( i ) ; Object o2 = other . get ( i ) ; if ( JSONNull . getInstance ( ) . equals ( o1 ) ) { if ( JSONNull . getInstance ( ) . equals ( o2 ) ) { continue ; } else { return false ; } } else { if ( JSONNull . getInstance ( ) . equals ( o2 ) ) { return false ; } } if ( o1 instanceof JSONArray && o2 instanceof JSONArray ) { JSONArray e = ( JSONArray ) o1 ; JSONArray a = ( JSONArray ) o2 ; if ( ! a . equals ( e ) ) { return false ; } } else { if ( o1 instanceof String && o2 instanceof JSONFunction ) { if ( ! o1 . equals ( String . valueOf ( o2 ) ) ) { return false ; } } else if ( o1 instanceof JSONFunction && o2 instanceof String ) { if ( ! o2 . equals ( String . valueOf ( o1 ) ) ) { return false ; } } else if ( o1 instanceof JSONObject && o2 instanceof JSONObject ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else if ( o1 instanceof JSONArray && o2 instanceof JSONArray ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else if ( o1 instanceof JSONFunction && o2 instanceof JSONFunction ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else { if ( o1 instanceof String ) { if ( ! o1 . equals ( String . valueOf ( o2 ) ) ) { return false ; } } else if ( o2 instanceof String ) { if ( ! o2 . equals ( String . valueOf ( o1 ) ) ) { return false ; } } else { Morpher m1 = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( o1 . getClass ( ) ) ; Morpher m2 = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( o2 . getClass ( ) ) ; if ( m1 != null && m1 != IdentityObjectMorpher . getInstance ( ) ) { if ( ! o1 . equals ( JSONUtils . getMorpherRegistry ( ) . morph ( o1 . getClass ( ) , o2 ) ) ) { return false ; } } else if ( m2 != null && m2 != IdentityObjectMorpher . getInstance ( ) ) { if ( ! JSONUtils . getMorpherRegistry ( ) . morph ( o1 . getClass ( ) , o1 ) . equals ( o2 ) ) { return false ; } } else { if ( ! o1 . equals ( o2 ) ) { return false ; } } } } } } return true ; } public Object get ( int index ) { return this . elements . get ( index ) ; } public boolean getBoolean ( int index ) { Object o = get ( index ) ; if ( o != null ) { if ( o . equals ( Boolean . FALSE ) || ( o instanceof String && ( ( String ) o ) . equalsIgnoreCase ( "<STR_LIT:false>" ) ) ) { return false ; } else if ( o . equals ( Boolean . TRUE ) || ( o instanceof String && ( ( String ) o ) . equalsIgnoreCase ( "<STR_LIT:true>" ) ) ) { return true ; } } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public double getDouble ( int index ) { Object o = get ( index ) ; if ( o != null ) { try { return o instanceof Number ? ( ( Number ) o ) . doubleValue ( ) : Double . parseDouble ( ( String ) o ) ; } catch ( Exception e ) { throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public int getInt ( int index ) { Object o = get ( index ) ; if ( o != null ) { return o instanceof Number ? ( ( Number ) o ) . intValue ( ) : ( int ) getDouble ( index ) ; } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public JSONArray getJSONArray ( int index ) { Object o = get ( index ) ; if ( o != null && o instanceof JSONArray ) { return ( JSONArray ) o ; } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public JSONObject getJSONObject ( int index ) { Object o = get ( index ) ; if ( JSONNull . getInstance ( ) . equals ( o ) ) { return new JSONObject ( true ) ; } else if ( o instanceof JSONObject ) { return ( JSONObject ) o ; } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public long getLong ( int index ) { Object o = get ( index ) ; if ( o != null ) { return o instanceof Number ? ( ( Number ) o ) . longValue ( ) : ( long ) getDouble ( index ) ; } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public String getString ( int index ) { Object o = get ( index ) ; if ( o != null ) { return o . toString ( ) ; } throw new JSONException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } public int hashCode ( ) { int hashcode = <NUM_LIT> ; for ( Iterator e = elements . iterator ( ) ; e . hasNext ( ) ; ) { Object element = e . next ( ) ; hashcode += JSONUtils . hashCode ( element ) ; } return hashcode ; } public int indexOf ( Object o ) { return elements . indexOf ( o ) ; } public boolean isArray ( ) { return true ; } public boolean isEmpty ( ) { return this . elements . isEmpty ( ) ; } public boolean isExpandElements ( ) { return expandElements ; } public Iterator iterator ( ) { return new JSONArrayListIterator ( ) ; } public String join ( String separator ) { return join ( separator , false ) ; } public String join ( String separator , boolean stripQuotes ) { int len = size ( ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < len ; i += <NUM_LIT:1> ) { if ( i > <NUM_LIT:0> ) { sb . append ( separator ) ; } String value = JSONUtils . valueToString ( this . elements . get ( i ) ) ; sb . append ( stripQuotes ? JSONUtils . stripQuotes ( value ) : value ) ; } return sb . toString ( ) ; } public int lastIndexOf ( Object o ) { return elements . lastIndexOf ( o ) ; } public ListIterator listIterator ( ) { return listIterator ( <NUM_LIT:0> ) ; } public ListIterator listIterator ( int index ) { if ( index < <NUM_LIT:0> || index > size ( ) ) throw new IndexOutOfBoundsException ( "<STR_LIT>" + index ) ; return new JSONArrayListIterator ( index ) ; } public Object opt ( int index ) { return ( index < <NUM_LIT:0> || index >= size ( ) ) ? null : this . elements . get ( index ) ; } public boolean optBoolean ( int index ) { return optBoolean ( index , false ) ; } public boolean optBoolean ( int index , boolean defaultValue ) { try { return getBoolean ( index ) ; } catch ( Exception e ) { return defaultValue ; } } public double optDouble ( int index ) { return optDouble ( index , Double . NaN ) ; } public double optDouble ( int index , double defaultValue ) { try { return getDouble ( index ) ; } catch ( Exception e ) { return defaultValue ; } } public int optInt ( int index ) { return optInt ( index , <NUM_LIT:0> ) ; } public int optInt ( int index , int defaultValue ) { try { return getInt ( index ) ; } catch ( Exception e ) { return defaultValue ; } } public JSONArray optJSONArray ( int index ) { Object o = opt ( index ) ; return o instanceof JSONArray ? ( JSONArray ) o : null ; } public JSONObject optJSONObject ( int index ) { Object o = opt ( index ) ; return o instanceof JSONObject ? ( JSONObject ) o : null ; } public long optLong ( int index ) { return optLong ( index , <NUM_LIT:0> ) ; } public long optLong ( int index , long defaultValue ) { try { return getLong ( index ) ; } catch ( Exception e ) { return defaultValue ; } } public String optString ( int index ) { return optString ( index , "<STR_LIT>" ) ; } public String optString ( int index , String defaultValue ) { Object o = opt ( index ) ; return o != null ? o . toString ( ) : defaultValue ; } public Object remove ( int index ) { return elements . remove ( index ) ; } public boolean remove ( Object o ) { return elements . remove ( o ) ; } public boolean removeAll ( Collection collection ) { return removeAll ( collection , new JsonConfig ( ) ) ; } public boolean removeAll ( Collection collection , JsonConfig jsonConfig ) { return elements . removeAll ( fromObject ( collection , jsonConfig ) ) ; } public boolean retainAll ( Collection collection ) { return retainAll ( collection , new JsonConfig ( ) ) ; } public boolean retainAll ( Collection collection , JsonConfig jsonConfig ) { return elements . retainAll ( fromObject ( collection , jsonConfig ) ) ; } public Object set ( int index , Object value ) { return set ( index , value , new JsonConfig ( ) ) ; } public Object set ( int index , Object value , JsonConfig jsonConfig ) { Object previous = get ( index ) ; element ( index , value , jsonConfig ) ; return previous ; } public void setExpandElements ( boolean expandElements ) { this . expandElements = expandElements ; } public int size ( ) { return this . elements . size ( ) ; } public List subList ( int fromIndex , int toIndex ) { return elements . subList ( fromIndex , toIndex ) ; } public Object [ ] toArray ( ) { return this . elements . toArray ( ) ; } public Object [ ] toArray ( Object [ ] array ) { return elements . toArray ( array ) ; } public JSONObject toJSONObject ( JSONArray names ) { if ( names == null || names . size ( ) == <NUM_LIT:0> || size ( ) == <NUM_LIT:0> ) { return null ; } JSONObject jo = new JSONObject ( ) ; for ( int i = <NUM_LIT:0> ; i < names . size ( ) ; i ++ ) { jo . element ( names . getString ( i ) , this . opt ( i ) ) ; } return jo ; } public String toString ( ) { try { return '<CHAR_LIT:[>' + join ( "<STR_LIT:U+002C>" ) + '<CHAR_LIT:]>' ; } catch ( Exception e ) { return null ; } } public String toString ( int indentFactor ) { if ( indentFactor == <NUM_LIT:0> ) { return this . toString ( ) ; } return toString ( indentFactor , <NUM_LIT:0> ) ; } public String toString ( int indentFactor , int indent ) { int len = size ( ) ; if ( len == <NUM_LIT:0> ) { return "<STR_LIT:[]>" ; } if ( indentFactor == <NUM_LIT:0> ) { return this . toString ( ) ; } int i ; StringBuffer sb = new StringBuffer ( "<STR_LIT:[>" ) ; if ( len == <NUM_LIT:1> ) { sb . append ( JSONUtils . valueToString ( this . elements . get ( <NUM_LIT:0> ) , indentFactor , indent ) ) ; } else { int newindent = indent + indentFactor ; sb . append ( '<STR_LIT:\n>' ) ; for ( i = <NUM_LIT:0> ; i < len ; i += <NUM_LIT:1> ) { if ( i > <NUM_LIT:0> ) { sb . append ( "<STR_LIT>" ) ; } for ( int j = <NUM_LIT:0> ; j < newindent ; j += <NUM_LIT:1> ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } sb . append ( JSONUtils . valueToString ( this . elements . get ( i ) , indentFactor , newindent ) ) ; } sb . append ( '<STR_LIT:\n>' ) ; for ( i = <NUM_LIT:0> ; i < indent ; i += <NUM_LIT:1> ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } for ( i = <NUM_LIT:0> ; i < indent ; i += <NUM_LIT:1> ) { sb . insert ( <NUM_LIT:0> , '<CHAR_LIT:U+0020>' ) ; } } sb . append ( '<CHAR_LIT:]>' ) ; return sb . toString ( ) ; } protected void write ( Writer writer , WritingVisitor visitor ) throws IOException { boolean b = false ; int len = size ( ) ; writer . write ( '<CHAR_LIT:[>' ) ; for ( int i = <NUM_LIT:0> ; i < len ; i += <NUM_LIT:1> ) { if ( b ) { writer . write ( '<CHAR_LIT:U+002C>' ) ; } Object v = this . elements . get ( i ) ; if ( v instanceof JSON ) { visitor . on ( ( JSON ) v , writer ) ; } else { visitor . on ( v , writer ) ; } b = true ; } writer . write ( '<CHAR_LIT:]>' ) ; } protected JSONArray addString ( String str ) { if ( str != null ) { elements . add ( str ) ; } return this ; } private JSONArray _addValue ( Object value , JsonConfig jsonConfig ) { this . elements . add ( value ) ; return this ; } protected Object _processValue ( Object value , JsonConfig jsonConfig ) { if ( value instanceof JSONTokener ) { return _fromJSONTokener ( ( JSONTokener ) value , jsonConfig ) ; } else if ( value != null && Enum . class . isAssignableFrom ( value . getClass ( ) ) ) { return ( ( Enum ) value ) . name ( ) ; } else if ( value instanceof Annotation || ( value != null && value . getClass ( ) . isAnnotation ( ) ) ) { throw new JSONException ( "<STR_LIT>" ) ; } return super . _processValue ( value , jsonConfig ) ; } private JSONArray addValue ( Object value , JsonConfig jsonConfig ) { return _addValue ( processValue ( value , jsonConfig ) , jsonConfig ) ; } private Object processValue ( Object value , JsonConfig jsonConfig ) { if ( value != null ) { JsonValueProcessor jsonValueProcessor = jsonConfig . findJsonValueProcessor ( value . getClass ( ) ) ; if ( jsonValueProcessor != null ) { value = jsonValueProcessor . processArrayValue ( value , jsonConfig ) ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } } return _processValue ( value , jsonConfig ) ; } private class JSONArrayListIterator implements ListIterator { int currentIndex = <NUM_LIT:0> ; int lastIndex = - <NUM_LIT:1> ; JSONArrayListIterator ( ) { } JSONArrayListIterator ( int index ) { currentIndex = index ; } public boolean hasNext ( ) { return currentIndex != size ( ) ; } public Object next ( ) { try { Object next = get ( currentIndex ) ; lastIndex = currentIndex ++ ; return next ; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException ( ) ; } } public void remove ( ) { if ( lastIndex == - <NUM_LIT:1> ) throw new IllegalStateException ( ) ; try { JSONArray . this . remove ( lastIndex ) ; if ( lastIndex < currentIndex ) { currentIndex -- ; } lastIndex = - <NUM_LIT:1> ; } catch ( IndexOutOfBoundsException e ) { throw new ConcurrentModificationException ( ) ; } } public boolean hasPrevious ( ) { return currentIndex != <NUM_LIT:0> ; } public Object previous ( ) { try { int index = currentIndex - <NUM_LIT:1> ; Object previous = get ( index ) ; lastIndex = currentIndex = index ; return previous ; } catch ( IndexOutOfBoundsException e ) { throw new NoSuchElementException ( ) ; } } public int nextIndex ( ) { return currentIndex ; } public int previousIndex ( ) { return currentIndex - <NUM_LIT:1> ; } public void set ( Object obj ) { if ( lastIndex == - <NUM_LIT:1> ) { throw new IllegalStateException ( ) ; } try { JSONArray . this . set ( lastIndex , obj ) ; } catch ( IndexOutOfBoundsException ex ) { throw new ConcurrentModificationException ( ) ; } } public void add ( Object obj ) { try { JSONArray . this . add ( currentIndex ++ , obj ) ; lastIndex = - <NUM_LIT:1> ; } catch ( IndexOutOfBoundsException ex ) { throw new ConcurrentModificationException ( ) ; } } } } </s>
<s> package net . sf . json ; import java . beans . PropertyDescriptor ; import java . io . IOException ; import java . io . Writer ; import java . lang . annotation . Annotation ; import java . lang . reflect . Array ; import java . lang . reflect . Field ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Modifier ; import java . util . ArrayList ; import java . lang . reflect . AnnotatedElement ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Iterator ; import java . util . LinkedHashMap ; import java . util . LinkedHashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . TreeMap ; import net . sf . ezmorph . Morpher ; import net . sf . ezmorph . array . ObjectArrayMorpher ; import net . sf . ezmorph . bean . BeanMorpher ; import net . sf . ezmorph . object . IdentityObjectMorpher ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; import net . sf . json . processors . JsonBeanProcessor ; import net . sf . json . processors . JsonValueProcessor ; import net . sf . json . processors . JsonVerifier ; import net . sf . json . processors . PropertyNameProcessor ; import net . sf . json . regexp . RegexpUtils ; import net . sf . json . util . CycleDetectionStrategy ; import net . sf . json . util . EnumMorpher ; import net . sf . json . util . JSONTokener ; import net . sf . json . util . JSONUtils ; import net . sf . json . util . PropertyFilter ; import net . sf . json . util . PropertySetStrategy ; import org . apache . commons . beanutils . DynaBean ; import org . apache . commons . beanutils . DynaProperty ; import org . apache . commons . beanutils . PropertyUtils ; import org . apache . commons . collections . map . ListOrderedMap ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; public final class JSONObject extends AbstractJSON implements JSON , Map < String , Object > , Comparable { private static final Log log = LogFactory . getLog ( JSONObject . class ) ; public static JSONObject fromObject ( Object object ) { return fromObject ( object , new JsonConfig ( ) ) ; } public static JSONObject fromObject ( Object object , JsonConfig jsonConfig ) { if ( object == null || JSONUtils . isNull ( object ) ) { return new JSONObject ( true ) ; } else if ( object instanceof Enum ) { throw new JSONException ( "<STR_LIT>" ) ; } else if ( object instanceof Annotation || ( object != null && object . getClass ( ) . isAnnotation ( ) ) ) { throw new JSONException ( "<STR_LIT>" ) ; } else if ( object instanceof JSONObject ) { return _fromJSONObject ( ( JSONObject ) object , jsonConfig ) ; } else if ( object instanceof DynaBean ) { return _fromDynaBean ( ( DynaBean ) object , jsonConfig ) ; } else if ( object instanceof JSONTokener ) { return _fromJSONTokener ( ( JSONTokener ) object , jsonConfig ) ; } else if ( object instanceof JSONString ) { return _fromJSONString ( ( JSONString ) object , jsonConfig ) ; } else if ( object instanceof Map ) { return _fromMap ( ( Map ) object , jsonConfig ) ; } else if ( object instanceof String ) { return _fromString ( ( String ) object , jsonConfig ) ; } else if ( JSONUtils . isNumber ( object ) || JSONUtils . isBoolean ( object ) || JSONUtils . isString ( object ) ) { return new JSONObject ( ) ; } else if ( JSONUtils . isArray ( object ) ) { throw new JSONException ( "<STR_LIT>" ) ; } else { return _fromBean ( object , jsonConfig ) ; } } public static Object toBean ( JSONObject jsonObject ) { if ( jsonObject == null || jsonObject . isNullObject ( ) ) { return null ; } DynaBean dynaBean = null ; JsonConfig jsonConfig = new JsonConfig ( ) ; Map props = JSONUtils . getProperties ( jsonObject ) ; dynaBean = JSONUtils . newDynaBean ( jsonObject , jsonConfig ) ; for ( Iterator entries = jsonObject . names ( jsonConfig ) . iterator ( ) ; entries . hasNext ( ) ; ) { String name = ( String ) entries . next ( ) ; String key = JSONUtils . convertToJavaIdentifier ( name , jsonConfig ) ; Class type = ( Class ) props . get ( name ) ; Object value = jsonObject . get ( name ) ; try { if ( ! JSONUtils . isNull ( value ) ) { if ( value instanceof JSONArray ) { dynaBean . set ( key , JSONArray . toCollection ( ( JSONArray ) value ) ) ; } else if ( String . class . isAssignableFrom ( type ) || Boolean . class . isAssignableFrom ( type ) || JSONUtils . isNumber ( type ) || Character . class . isAssignableFrom ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { dynaBean . set ( key , value ) ; } else { dynaBean . set ( key , toBean ( ( JSONObject ) value ) ) ; } } else { if ( type . isPrimitive ( ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) ) ; dynaBean . set ( key , JSONUtils . getMorpherRegistry ( ) . morph ( type , null ) ) ; } else { dynaBean . set ( key , null ) ; } } } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( "<STR_LIT>" + name + "<STR_LIT>" + type , e ) ; } } return dynaBean ; } public static Object toBean ( JSONObject jsonObject , Class beanClass ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( beanClass ) ; return toBean ( jsonObject , jsonConfig ) ; } public static Object toBean ( JSONObject jsonObject , Class beanClass , Map classMap ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setRootClass ( beanClass ) ; jsonConfig . setClassMap ( classMap ) ; return toBean ( jsonObject , jsonConfig ) ; } public static Object toBean ( JSONObject jsonObject , JsonConfig jsonConfig ) { if ( jsonObject == null || jsonObject . isNullObject ( ) ) { return null ; } Class beanClass = jsonConfig . getRootClass ( ) ; Map classMap = jsonConfig . getClassMap ( ) ; if ( beanClass == null ) { return toBean ( jsonObject ) ; } if ( classMap == null ) { classMap = Collections . EMPTY_MAP ; } Object bean = null ; try { if ( beanClass . isInterface ( ) ) { if ( ! Map . class . isAssignableFrom ( beanClass ) ) { throw new JSONException ( "<STR_LIT>" + beanClass ) ; } else { bean = new HashMap ( ) ; } } else { bean = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( beanClass , jsonObject ) ; } } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( e ) ; } Map props = JSONUtils . getProperties ( jsonObject ) ; PropertyFilter javaPropertyFilter = jsonConfig . getJavaPropertyFilter ( ) ; for ( Iterator entries = jsonObject . names ( jsonConfig ) . iterator ( ) ; entries . hasNext ( ) ; ) { String name = ( String ) entries . next ( ) ; Class type = ( Class ) props . get ( name ) ; Object value = jsonObject . get ( name ) ; if ( javaPropertyFilter != null && javaPropertyFilter . apply ( bean , name , value ) ) { continue ; } String key = Map . class . isAssignableFrom ( beanClass ) && jsonConfig . isSkipJavaIdentifierTransformationInMapKeys ( ) ? name : JSONUtils . convertToJavaIdentifier ( name , jsonConfig ) ; PropertyNameProcessor propertyNameProcessor = jsonConfig . findJavaPropertyNameProcessor ( beanClass ) ; if ( propertyNameProcessor != null ) { key = propertyNameProcessor . processPropertyName ( beanClass , key ) ; } try { if ( Map . class . isAssignableFrom ( beanClass ) ) { if ( JSONUtils . isNull ( value ) ) { setProperty ( bean , key , value , jsonConfig ) ; } else if ( value instanceof JSONArray ) { setProperty ( bean , key , convertPropertyValueToCollection ( key , value , jsonConfig , name , classMap , List . class ) , jsonConfig ) ; } else if ( String . class . isAssignableFrom ( type ) || JSONUtils . isBoolean ( type ) || JSONUtils . isNumber ( type ) || JSONUtils . isString ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( jsonConfig . isHandleJettisonEmptyElement ( ) && "<STR_LIT>" . equals ( value ) ) { setProperty ( bean , key , null , jsonConfig ) ; } else { setProperty ( bean , key , value , jsonConfig ) ; } } else { Class targetClass = resolveClass ( classMap , key , name , type ) ; JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( targetClass ) ; jsc . setClassMap ( classMap ) ; if ( targetClass != null ) { setProperty ( bean , key , toBean ( ( JSONObject ) value , jsc ) , jsonConfig ) ; } else { setProperty ( bean , key , toBean ( ( JSONObject ) value ) , jsonConfig ) ; } } } else { PropertyDescriptor pd = PropertyUtils . getPropertyDescriptor ( bean , key ) ; if ( pd != null && pd . getWriteMethod ( ) == null ) { log . info ( "<STR_LIT>" + key + "<STR_LIT>" + bean . getClass ( ) + "<STR_LIT>" ) ; continue ; } if ( pd != null ) { Class targetType = pd . getPropertyType ( ) ; if ( ! JSONUtils . isNull ( value ) ) { if ( value instanceof JSONArray ) { if ( List . class . isAssignableFrom ( pd . getPropertyType ( ) ) ) { setProperty ( bean , key , convertPropertyValueToCollection ( key , value , jsonConfig , name , classMap , pd . getPropertyType ( ) ) , jsonConfig ) ; } else if ( Set . class . isAssignableFrom ( pd . getPropertyType ( ) ) ) { setProperty ( bean , key , convertPropertyValueToCollection ( key , value , jsonConfig , name , classMap , pd . getPropertyType ( ) ) , jsonConfig ) ; } else { setProperty ( bean , key , convertPropertyValueToArray ( key , value , targetType , jsonConfig , classMap ) , jsonConfig ) ; } } else if ( String . class . isAssignableFrom ( type ) || JSONUtils . isBoolean ( type ) || JSONUtils . isNumber ( type ) || JSONUtils . isString ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( pd != null ) { if ( jsonConfig . isHandleJettisonEmptyElement ( ) && "<STR_LIT>" . equals ( value ) ) { setProperty ( bean , key , null , jsonConfig ) ; } else if ( ! targetType . isInstance ( value ) ) { setProperty ( bean , key , morphPropertyValue ( key , value , type , targetType ) , jsonConfig ) ; } else { setProperty ( bean , key , value , jsonConfig ) ; } } else if ( beanClass == null || bean instanceof Map ) { setProperty ( bean , key , value , jsonConfig ) ; } else { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) + "<STR_LIT>" + bean . getClass ( ) . getName ( ) ) ; } } else { if ( jsonConfig . isHandleJettisonSingleElementArray ( ) ) { JSONArray array = new JSONArray ( ) . element ( value , jsonConfig ) ; Class newTargetClass = resolveClass ( classMap , key , name , type ) ; JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( newTargetClass ) ; jsc . setClassMap ( classMap ) ; if ( targetType . isArray ( ) ) { setProperty ( bean , key , JSONArray . toArray ( array , jsc ) , jsonConfig ) ; } else if ( JSONArray . class . isAssignableFrom ( targetType ) ) { setProperty ( bean , key , array , jsonConfig ) ; } else if ( List . class . isAssignableFrom ( targetType ) || Set . class . isAssignableFrom ( targetType ) ) { jsc . setCollectionType ( targetType ) ; setProperty ( bean , key , JSONArray . toCollection ( array , jsc ) , jsonConfig ) ; } else { setProperty ( bean , key , toBean ( ( JSONObject ) value , jsc ) , jsonConfig ) ; } } else { if ( targetType == Object . class || targetType . isInterface ( ) ) { Class targetTypeCopy = targetType ; targetType = findTargetClass ( key , classMap ) ; targetType = targetType == null ? findTargetClass ( name , classMap ) : targetType ; targetType = targetType == null && targetTypeCopy . isInterface ( ) ? targetTypeCopy : targetType ; } JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( targetType ) ; jsc . setClassMap ( classMap ) ; setProperty ( bean , key , toBean ( ( JSONObject ) value , jsc ) , jsonConfig ) ; } } } else { if ( type . isPrimitive ( ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) ) ; setProperty ( bean , key , JSONUtils . getMorpherRegistry ( ) . morph ( type , null ) , jsonConfig ) ; } else { setProperty ( bean , key , null , jsonConfig ) ; } } } else { if ( ! JSONUtils . isNull ( value ) ) { if ( value instanceof JSONArray ) { setProperty ( bean , key , convertPropertyValueToCollection ( key , value , jsonConfig , name , classMap , List . class ) , jsonConfig ) ; } else if ( String . class . isAssignableFrom ( type ) || JSONUtils . isBoolean ( type ) || JSONUtils . isNumber ( type ) || JSONUtils . isString ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( beanClass == null || bean instanceof Map || jsonConfig . getPropertySetStrategy ( ) != null || ! jsonConfig . isIgnorePublicFields ( ) ) { setProperty ( bean , key , value , jsonConfig ) ; } else { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) + "<STR_LIT>" + bean . getClass ( ) . getName ( ) ) ; } } else { if ( jsonConfig . isHandleJettisonSingleElementArray ( ) ) { Class newTargetClass = resolveClass ( classMap , key , name , type ) ; JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( newTargetClass ) ; jsc . setClassMap ( classMap ) ; setProperty ( bean , key , toBean ( ( JSONObject ) value , jsc ) , jsonConfig ) ; } else { setProperty ( bean , key , value , jsonConfig ) ; } } } else { if ( type . isPrimitive ( ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) ) ; setProperty ( bean , key , JSONUtils . getMorpherRegistry ( ) . morph ( type , null ) , jsonConfig ) ; } else { setProperty ( bean , key , null , jsonConfig ) ; } } } } } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( "<STR_LIT>" + name + "<STR_LIT>" + type , e ) ; } } return bean ; } public static Object toBean ( JSONObject jsonObject , Object root , JsonConfig jsonConfig ) { if ( jsonObject == null || jsonObject . isNullObject ( ) || root == null ) { return root ; } Class rootClass = root . getClass ( ) ; if ( rootClass . isInterface ( ) ) { throw new JSONException ( "<STR_LIT>" + rootClass ) ; } Map classMap = jsonConfig . getClassMap ( ) ; if ( classMap == null ) { classMap = Collections . EMPTY_MAP ; } Map props = JSONUtils . getProperties ( jsonObject ) ; PropertyFilter javaPropertyFilter = jsonConfig . getJavaPropertyFilter ( ) ; for ( Iterator entries = jsonObject . names ( jsonConfig ) . iterator ( ) ; entries . hasNext ( ) ; ) { String name = ( String ) entries . next ( ) ; Class type = ( Class ) props . get ( name ) ; Object value = jsonObject . get ( name ) ; if ( javaPropertyFilter != null && javaPropertyFilter . apply ( root , name , value ) ) { continue ; } String key = JSONUtils . convertToJavaIdentifier ( name , jsonConfig ) ; try { PropertyDescriptor pd = PropertyUtils . getPropertyDescriptor ( root , key ) ; if ( pd != null && pd . getWriteMethod ( ) == null ) { log . info ( "<STR_LIT>" + key + "<STR_LIT>" + root . getClass ( ) + "<STR_LIT>" ) ; continue ; } if ( ! JSONUtils . isNull ( value ) ) { if ( value instanceof JSONArray ) { if ( pd == null || List . class . isAssignableFrom ( pd . getPropertyType ( ) ) ) { Class targetClass = resolveClass ( classMap , key , name , type ) ; Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( targetClass , null ) ; List list = JSONArray . toList ( ( JSONArray ) value , newRoot , jsonConfig ) ; setProperty ( root , key , list , jsonConfig ) ; } else { Class innerType = JSONUtils . getInnerComponentType ( pd . getPropertyType ( ) ) ; Class targetInnerType = findTargetClass ( key , classMap ) ; if ( innerType . equals ( Object . class ) && targetInnerType != null && ! targetInnerType . equals ( Object . class ) ) { innerType = targetInnerType ; } Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( innerType , null ) ; Object array = JSONArray . toArray ( ( JSONArray ) value , newRoot , jsonConfig ) ; if ( innerType . isPrimitive ( ) || JSONUtils . isNumber ( innerType ) || Boolean . class . isAssignableFrom ( innerType ) || JSONUtils . isString ( innerType ) ) { array = JSONUtils . getMorpherRegistry ( ) . morph ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) , array ) ; } else if ( ! array . getClass ( ) . equals ( pd . getPropertyType ( ) ) ) { if ( ! pd . getPropertyType ( ) . equals ( Object . class ) ) { Morpher morpher = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) ) ; if ( IdentityObjectMorpher . getInstance ( ) . equals ( morpher ) ) { ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher ( new BeanMorpher ( innerType , JSONUtils . getMorpherRegistry ( ) ) ) ; JSONUtils . getMorpherRegistry ( ) . registerMorpher ( beanMorpher ) ; } array = JSONUtils . getMorpherRegistry ( ) . morph ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) , array ) ; } } setProperty ( root , key , array , jsonConfig ) ; } } else if ( String . class . isAssignableFrom ( type ) || JSONUtils . isBoolean ( type ) || JSONUtils . isNumber ( type ) || JSONUtils . isString ( type ) || JSONFunction . class . isAssignableFrom ( type ) ) { if ( pd != null ) { if ( jsonConfig . isHandleJettisonEmptyElement ( ) && "<STR_LIT>" . equals ( value ) ) { setProperty ( root , key , null , jsonConfig ) ; } else if ( ! pd . getPropertyType ( ) . isInstance ( value ) ) { Morpher morpher = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( pd . getPropertyType ( ) ) ; if ( IdentityObjectMorpher . getInstance ( ) . equals ( morpher ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT>" + type . getName ( ) + "<STR_LIT>" + pd . getPropertyType ( ) . getName ( ) + "<STR_LIT>" ) ; JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new BeanMorpher ( pd . getPropertyType ( ) , JSONUtils . getMorpherRegistry ( ) ) ) ; } setProperty ( root , key , JSONUtils . getMorpherRegistry ( ) . morph ( pd . getPropertyType ( ) , value ) , jsonConfig ) ; } else { setProperty ( root , key , value , jsonConfig ) ; } } else if ( root instanceof Map ) { setProperty ( root , key , value , jsonConfig ) ; } else { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) + "<STR_LIT>" + root . getClass ( ) . getName ( ) ) ; } } else { if ( pd != null ) { Class targetClass = pd . getPropertyType ( ) ; if ( jsonConfig . isHandleJettisonSingleElementArray ( ) ) { JSONArray array = new JSONArray ( ) . element ( value , jsonConfig ) ; Class newTargetClass = resolveClass ( classMap , key , name , type ) ; Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( newTargetClass , ( JSONObject ) value ) ; if ( targetClass . isArray ( ) ) { setProperty ( root , key , JSONArray . toArray ( array , newRoot , jsonConfig ) , jsonConfig ) ; } else if ( Collection . class . isAssignableFrom ( targetClass ) ) { setProperty ( root , key , JSONArray . toList ( array , newRoot , jsonConfig ) , jsonConfig ) ; } else if ( JSONArray . class . isAssignableFrom ( targetClass ) ) { setProperty ( root , key , array , jsonConfig ) ; } else { setProperty ( root , key , toBean ( ( JSONObject ) value , newRoot , jsonConfig ) , jsonConfig ) ; } } else { if ( targetClass == Object . class ) { targetClass = resolveClass ( classMap , key , name , type ) ; if ( targetClass == null ) { targetClass = Object . class ; } } Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( targetClass , ( JSONObject ) value ) ; setProperty ( root , key , toBean ( ( JSONObject ) value , newRoot , jsonConfig ) , jsonConfig ) ; } } else if ( root instanceof Map ) { Class targetClass = findTargetClass ( key , classMap ) ; targetClass = targetClass == null ? findTargetClass ( name , classMap ) : targetClass ; Object newRoot = jsonConfig . getNewBeanInstanceStrategy ( ) . newInstance ( targetClass , null ) ; setProperty ( root , key , toBean ( ( JSONObject ) value , newRoot , jsonConfig ) , jsonConfig ) ; } else { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) + "<STR_LIT>" + rootClass . getName ( ) ) ; } } } else { if ( type . isPrimitive ( ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT::>" + type . getName ( ) ) ; setProperty ( root , key , JSONUtils . getMorpherRegistry ( ) . morph ( type , null ) , jsonConfig ) ; } else { setProperty ( root , key , null , jsonConfig ) ; } } } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( "<STR_LIT>" + name + "<STR_LIT>" + type , e ) ; } } return root ; } private static JSONObject _fromBean ( Object bean , JsonConfig jsonConfig ) { if ( ! addInstance ( bean ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsObject ( bean ) ; } catch ( JSONException jsone ) { removeInstance ( bean ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( bean ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireObjectStartEvent ( jsonConfig ) ; JsonBeanProcessor processor = jsonConfig . findJsonBeanProcessor ( bean . getClass ( ) ) ; if ( processor != null ) { JSONObject json = null ; try { json = processor . processBean ( bean , jsonConfig ) ; if ( json == null ) { json = ( JSONObject ) jsonConfig . findDefaultValueProcessor ( bean . getClass ( ) ) . getDefaultValue ( bean . getClass ( ) ) ; if ( json == null ) { json = new JSONObject ( true ) ; } } removeInstance ( bean ) ; fireObjectEndEvent ( jsonConfig ) ; } catch ( JSONException jsone ) { removeInstance ( bean ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( bean ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } return json ; } JSONObject jsonObject = defaultBeanProcessing ( bean , jsonConfig ) ; removeInstance ( bean ) ; fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } private static JSONObject defaultBeanProcessing ( Object bean , JsonConfig jsonConfig ) { Class beanClass = bean . getClass ( ) ; PropertyNameProcessor propertyNameProcessor = jsonConfig . findJsonPropertyNameProcessor ( beanClass ) ; Collection exclusions = jsonConfig . getMergedExcludes ( beanClass ) ; JSONObject jsonObject = new JSONObject ( ) ; try { PropertyDescriptor [ ] pds = PropertyUtils . getPropertyDescriptors ( bean ) ; PropertyFilter jsonPropertyFilter = jsonConfig . getJsonPropertyFilter ( ) ; for ( int i = <NUM_LIT:0> ; i < pds . length ; i ++ ) { boolean bypass = false ; String key = pds [ i ] . getName ( ) ; if ( exclusions . contains ( key ) ) { continue ; } if ( jsonConfig . isIgnoreTransientFields ( ) && isTransientField ( key , beanClass , jsonConfig ) ) { continue ; } Class type = pds [ i ] . getPropertyType ( ) ; try { pds [ i ] . getReadMethod ( ) ; } catch ( Exception e ) { String warning = "<STR_LIT>" + key + "<STR_LIT>" + beanClass + "<STR_LIT>" ; fireWarnEvent ( warning , jsonConfig ) ; log . info ( warning ) ; continue ; } if ( pds [ i ] . getReadMethod ( ) != null ) { if ( isTransient ( pds [ i ] . getReadMethod ( ) , jsonConfig ) ) continue ; Object value = PropertyUtils . getProperty ( bean , key ) ; if ( jsonPropertyFilter != null && jsonPropertyFilter . apply ( bean , key , value ) ) { continue ; } JsonValueProcessor jsonValueProcessor = jsonConfig . findJsonValueProcessor ( beanClass , type , key ) ; if ( jsonValueProcessor != null ) { value = jsonValueProcessor . processObjectValue ( key , value , jsonConfig ) ; bypass = true ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } if ( propertyNameProcessor != null ) { key = propertyNameProcessor . processPropertyName ( beanClass , key ) ; } setValue ( jsonObject , key , value , type , jsonConfig , bypass ) ; } else { String warning = "<STR_LIT>" + key + "<STR_LIT>" + beanClass + "<STR_LIT>" ; fireWarnEvent ( warning , jsonConfig ) ; log . info ( warning ) ; } } try { if ( ! jsonConfig . isIgnorePublicFields ( ) ) { Field [ ] fields = beanClass . getFields ( ) ; for ( int i = <NUM_LIT:0> ; i < fields . length ; i ++ ) { boolean bypass = false ; Field field = fields [ i ] ; String key = field . getName ( ) ; if ( exclusions . contains ( key ) ) { continue ; } if ( jsonConfig . isIgnoreTransientFields ( ) && isTransient ( field , jsonConfig ) ) { continue ; } Class type = field . getType ( ) ; Object value = field . get ( bean ) ; if ( jsonPropertyFilter != null && jsonPropertyFilter . apply ( bean , key , value ) ) { continue ; } JsonValueProcessor jsonValueProcessor = jsonConfig . findJsonValueProcessor ( beanClass , type , key ) ; if ( jsonValueProcessor != null ) { value = jsonValueProcessor . processObjectValue ( key , value , jsonConfig ) ; bypass = true ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } if ( propertyNameProcessor != null ) { key = propertyNameProcessor . processPropertyName ( beanClass , key ) ; } setValue ( jsonObject , key , value , type , jsonConfig , bypass ) ; } } } catch ( Exception e ) { log . trace ( "<STR_LIT>" , e ) ; } } catch ( JSONException jsone ) { removeInstance ( bean ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( Exception e ) { removeInstance ( bean ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } return jsonObject ; } private static JSONObject _fromDynaBean ( DynaBean bean , JsonConfig jsonConfig ) { if ( bean == null ) { fireObjectStartEvent ( jsonConfig ) ; fireObjectEndEvent ( jsonConfig ) ; return new JSONObject ( true ) ; } if ( ! addInstance ( bean ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsObject ( bean ) ; } catch ( JSONException jsone ) { removeInstance ( bean ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( bean ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireObjectStartEvent ( jsonConfig ) ; JSONObject jsonObject = new JSONObject ( ) ; try { DynaProperty [ ] props = bean . getDynaClass ( ) . getDynaProperties ( ) ; Collection exclusions = jsonConfig . getMergedExcludes ( ) ; PropertyFilter jsonPropertyFilter = jsonConfig . getJsonPropertyFilter ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { boolean bypass = false ; DynaProperty dynaProperty = props [ i ] ; String key = dynaProperty . getName ( ) ; if ( exclusions . contains ( key ) ) { continue ; } Class type = dynaProperty . getType ( ) ; Object value = bean . get ( dynaProperty . getName ( ) ) ; if ( jsonPropertyFilter != null && jsonPropertyFilter . apply ( bean , key , value ) ) { continue ; } JsonValueProcessor jsonValueProcessor = jsonConfig . findJsonValueProcessor ( type , key ) ; if ( jsonValueProcessor != null ) { value = jsonValueProcessor . processObjectValue ( key , value , jsonConfig ) ; bypass = true ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } setValue ( jsonObject , key , value , type , jsonConfig , bypass ) ; } } catch ( JSONException jsone ) { removeInstance ( bean ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( bean ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( bean ) ; fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } private static JSONObject _fromJSONObject ( JSONObject object , JsonConfig jsonConfig ) { if ( object == null || object . isNullObject ( ) ) { fireObjectStartEvent ( jsonConfig ) ; fireObjectEndEvent ( jsonConfig ) ; return new JSONObject ( true ) ; } if ( ! addInstance ( object ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsObject ( object ) ; } catch ( JSONException jsone ) { removeInstance ( object ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( object ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireObjectStartEvent ( jsonConfig ) ; JSONArray sa = object . names ( jsonConfig ) ; Collection exclusions = jsonConfig . getMergedExcludes ( ) ; JSONObject jsonObject = new JSONObject ( ) ; PropertyFilter jsonPropertyFilter = jsonConfig . getJsonPropertyFilter ( ) ; for ( Iterator i = sa . iterator ( ) ; i . hasNext ( ) ; ) { Object k = i . next ( ) ; if ( k == null ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( ! ( k instanceof String ) && ! jsonConfig . isAllowNonStringKeys ( ) ) { throw new ClassCastException ( "<STR_LIT>" ) ; } String key = String . valueOf ( k ) ; if ( "<STR_LIT:null>" . equals ( key ) ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( exclusions . contains ( key ) ) { continue ; } Object value = object . opt ( key ) ; if ( jsonPropertyFilter != null && jsonPropertyFilter . apply ( object , key , value ) ) { continue ; } if ( jsonObject . properties . containsKey ( key ) ) { jsonObject . accumulate ( key , value , jsonConfig ) ; firePropertySetEvent ( key , value , true , jsonConfig ) ; } else { jsonObject . setInternal ( key , value , jsonConfig ) ; firePropertySetEvent ( key , value , false , jsonConfig ) ; } } removeInstance ( object ) ; fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } private static JSONObject _fromJSONString ( JSONString string , JsonConfig jsonConfig ) { return _fromJSONTokener ( new JSONTokener ( string . toJSONString ( ) ) , jsonConfig ) ; } private static JSONObject _fromJSONTokener ( JSONTokener tokener , JsonConfig jsonConfig ) { try { char c ; String key ; Object value ; if ( tokener . matches ( "<STR_LIT>" ) ) { fireObjectStartEvent ( jsonConfig ) ; fireObjectEndEvent ( jsonConfig ) ; return new JSONObject ( true ) ; } if ( tokener . nextClean ( ) != '<CHAR_LIT>' ) { throw tokener . syntaxError ( "<STR_LIT>" ) ; } fireObjectStartEvent ( jsonConfig ) ; Collection exclusions = jsonConfig . getMergedExcludes ( ) ; PropertyFilter jsonPropertyFilter = jsonConfig . getJsonPropertyFilter ( ) ; JSONObject jsonObject = new JSONObject ( ) ; for ( ; ; ) { c = tokener . nextClean ( ) ; switch ( c ) { case <NUM_LIT:0> : throw tokener . syntaxError ( "<STR_LIT>" ) ; case '<CHAR_LIT:}>' : fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; default : tokener . back ( ) ; key = tokener . nextValue ( jsonConfig ) . toString ( ) ; } c = tokener . nextClean ( ) ; if ( c == '<CHAR_LIT:=>' ) { if ( tokener . next ( ) != '<CHAR_LIT:>>' ) { tokener . back ( ) ; } } else if ( c != '<CHAR_LIT::>' ) { throw tokener . syntaxError ( "<STR_LIT>" ) ; } char peek = tokener . peek ( ) ; boolean quoted = peek == '<CHAR_LIT:">' || peek == '<STR_LIT>' ; Object v = tokener . nextValue ( jsonConfig ) ; if ( quoted || ! JSONUtils . isFunctionHeader ( v ) ) { if ( exclusions . contains ( key ) ) { switch ( tokener . nextClean ( ) ) { case '<CHAR_LIT:;>' : case '<CHAR_LIT:U+002C>' : if ( tokener . nextClean ( ) == '<CHAR_LIT:}>' ) { fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } tokener . back ( ) ; break ; case '<CHAR_LIT:}>' : fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; default : throw tokener . syntaxError ( "<STR_LIT>" ) ; } continue ; } if ( jsonPropertyFilter == null || ! jsonPropertyFilter . apply ( tokener , key , v ) ) { if ( quoted && v instanceof String && ( JSONUtils . mayBeJSON ( ( String ) v ) || JSONUtils . isFunction ( v ) ) ) { v = JSONUtils . DOUBLE_QUOTE + v + JSONUtils . DOUBLE_QUOTE ; } if ( jsonObject . properties . containsKey ( key ) ) { jsonObject . accumulate ( key , v , jsonConfig ) ; firePropertySetEvent ( key , v , true , jsonConfig ) ; } else { jsonObject . element ( key , v , jsonConfig ) ; firePropertySetEvent ( key , v , false , jsonConfig ) ; } } } else { String params = JSONUtils . getFunctionParams ( ( String ) v ) ; int i = <NUM_LIT:0> ; StringBuffer sb = new StringBuffer ( ) ; for ( ; ; ) { char ch = tokener . next ( ) ; if ( ch == <NUM_LIT:0> ) { break ; } if ( ch == '<CHAR_LIT>' ) { i ++ ; } if ( ch == '<CHAR_LIT:}>' ) { i -- ; } sb . append ( ch ) ; if ( i == <NUM_LIT:0> ) { break ; } } if ( i != <NUM_LIT:0> ) { throw tokener . syntaxError ( "<STR_LIT>" + v ) ; } String text = sb . toString ( ) ; text = text . substring ( <NUM_LIT:1> , text . length ( ) - <NUM_LIT:1> ) . trim ( ) ; value = new JSONFunction ( ( params != null ) ? StringUtils . split ( params , "<STR_LIT:U+002C>" ) : null , text ) ; if ( jsonPropertyFilter == null || ! jsonPropertyFilter . apply ( tokener , key , value ) ) { if ( jsonObject . properties . containsKey ( key ) ) { jsonObject . accumulate ( key , value , jsonConfig ) ; firePropertySetEvent ( key , value , true , jsonConfig ) ; } else { jsonObject . element ( key , value , jsonConfig ) ; firePropertySetEvent ( key , value , false , jsonConfig ) ; } } } switch ( tokener . nextClean ( ) ) { case '<CHAR_LIT:;>' : case '<CHAR_LIT:U+002C>' : if ( tokener . nextClean ( ) == '<CHAR_LIT:}>' ) { fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } tokener . back ( ) ; break ; case '<CHAR_LIT:}>' : fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; default : throw tokener . syntaxError ( "<STR_LIT>" ) ; } } } catch ( JSONException jsone ) { fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } private static JSONObject _fromMap ( Map map , JsonConfig jsonConfig ) { if ( map == null ) { fireObjectStartEvent ( jsonConfig ) ; fireObjectEndEvent ( jsonConfig ) ; return new JSONObject ( true ) ; } if ( ! addInstance ( map ) ) { try { return jsonConfig . getCycleDetectionStrategy ( ) . handleRepeatedReferenceAsObject ( map ) ; } catch ( JSONException jsone ) { removeInstance ( map ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( map ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } } fireObjectStartEvent ( jsonConfig ) ; Collection exclusions = jsonConfig . getMergedExcludes ( ) ; JSONObject jsonObject = new JSONObject ( ) ; PropertyFilter jsonPropertyFilter = jsonConfig . getJsonPropertyFilter ( ) ; try { for ( Iterator entries = map . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { boolean bypass = false ; Map . Entry entry = ( Map . Entry ) entries . next ( ) ; Object k = entry . getKey ( ) ; if ( k == null ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( ! ( k instanceof String ) && ! jsonConfig . isAllowNonStringKeys ( ) ) { throw new ClassCastException ( "<STR_LIT>" ) ; } String key = String . valueOf ( k ) ; if ( "<STR_LIT:null>" . equals ( key ) ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( exclusions . contains ( key ) ) { continue ; } Object value = entry . getValue ( ) ; if ( jsonPropertyFilter != null && jsonPropertyFilter . apply ( map , key , value ) ) { continue ; } if ( value != null ) { JsonValueProcessor jsonValueProcessor = jsonConfig . findJsonValueProcessor ( value . getClass ( ) , key ) ; if ( jsonValueProcessor != null ) { value = jsonValueProcessor . processObjectValue ( key , value , jsonConfig ) ; bypass = true ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } setValue ( jsonObject , key , value , value . getClass ( ) , jsonConfig , bypass ) ; } else { if ( jsonObject . properties . containsKey ( key ) ) { jsonObject . accumulate ( key , JSONNull . getInstance ( ) ) ; firePropertySetEvent ( key , JSONNull . getInstance ( ) , true , jsonConfig ) ; } else { jsonObject . element ( key , JSONNull . getInstance ( ) ) ; firePropertySetEvent ( key , JSONNull . getInstance ( ) , false , jsonConfig ) ; } } } } catch ( JSONException jsone ) { removeInstance ( map ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } catch ( RuntimeException e ) { removeInstance ( map ) ; JSONException jsone = new JSONException ( e ) ; fireErrorEvent ( jsone , jsonConfig ) ; throw jsone ; } removeInstance ( map ) ; fireObjectEndEvent ( jsonConfig ) ; return jsonObject ; } private static JSONObject _fromString ( String str , JsonConfig jsonConfig ) { if ( str == null || "<STR_LIT:null>" . equals ( str ) ) { fireObjectStartEvent ( jsonConfig ) ; fireObjectEndEvent ( jsonConfig ) ; return new JSONObject ( true ) ; } return _fromJSONTokener ( new JSONTokener ( str ) , jsonConfig ) ; } private static Object convertPropertyValueToArray ( String key , Object value , Class targetType , JsonConfig jsonConfig , Map classMap ) { Class innerType = JSONUtils . getInnerComponentType ( targetType ) ; Class targetInnerType = findTargetClass ( key , classMap ) ; if ( innerType . equals ( Object . class ) && targetInnerType != null && ! targetInnerType . equals ( Object . class ) ) { innerType = targetInnerType ; } JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( innerType ) ; jsc . setClassMap ( classMap ) ; Object array = JSONArray . toArray ( ( JSONArray ) value , jsc ) ; if ( innerType . isPrimitive ( ) || JSONUtils . isNumber ( innerType ) || Boolean . class . isAssignableFrom ( innerType ) || JSONUtils . isString ( innerType ) ) { array = JSONUtils . getMorpherRegistry ( ) . morph ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) , array ) ; } else if ( ! array . getClass ( ) . equals ( targetType ) ) { if ( ! targetType . equals ( Object . class ) ) { Morpher morpher = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) ) ; if ( IdentityObjectMorpher . getInstance ( ) . equals ( morpher ) ) { ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher ( new BeanMorpher ( innerType , JSONUtils . getMorpherRegistry ( ) ) ) ; JSONUtils . getMorpherRegistry ( ) . registerMorpher ( beanMorpher ) ; } array = JSONUtils . getMorpherRegistry ( ) . morph ( Array . newInstance ( innerType , <NUM_LIT:0> ) . getClass ( ) , array ) ; } } return array ; } private static List convertPropertyValueToList ( String key , Object value , JsonConfig jsonConfig , String name , Map classMap ) { Class targetClass = findTargetClass ( key , classMap ) ; targetClass = targetClass == null ? findTargetClass ( name , classMap ) : targetClass ; JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( targetClass ) ; jsc . setClassMap ( classMap ) ; List list = ( List ) JSONArray . toCollection ( ( JSONArray ) value , jsc ) ; return list ; } private static Collection convertPropertyValueToCollection ( String key , Object value , JsonConfig jsonConfig , String name , Map classMap , Class collectionType ) { Class targetClass = findTargetClass ( key , classMap ) ; targetClass = targetClass == null ? findTargetClass ( name , classMap ) : targetClass ; JsonConfig jsc = jsonConfig . copy ( ) ; jsc . setRootClass ( targetClass ) ; jsc . setClassMap ( classMap ) ; jsc . setCollectionType ( collectionType ) ; return JSONArray . toCollection ( ( JSONArray ) value , jsc ) ; } private static Class resolveClass ( Map classMap , String key , String name , Class type ) { Class targetClass = findTargetClass ( key , classMap ) ; if ( targetClass == null ) { targetClass = findTargetClass ( name , classMap ) ; } if ( targetClass == null && type != null ) { if ( List . class . equals ( type ) ) { targetClass = ArrayList . class ; } else if ( Map . class . equals ( type ) ) { targetClass = LinkedHashMap . class ; } else if ( Set . class . equals ( type ) ) { targetClass = LinkedHashSet . class ; } else if ( ! type . isInterface ( ) && ! Object . class . equals ( type ) ) { targetClass = type ; } } return targetClass ; } private static Class findTargetClass ( String key , Map classMap ) { Class targetClass = ( Class ) classMap . get ( key ) ; if ( targetClass == null ) { for ( Iterator i = classMap . entrySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) i . next ( ) ; if ( RegexpUtils . getMatcher ( ( String ) entry . getKey ( ) ) . matches ( key ) ) { targetClass = ( Class ) entry . getValue ( ) ; break ; } } } return targetClass ; } private static boolean isTransientField ( String name , Class beanClass , JsonConfig jsonConfig ) { try { Field field = beanClass . getDeclaredField ( name ) ; if ( ( field . getModifiers ( ) & Modifier . TRANSIENT ) == Modifier . TRANSIENT ) return true ; return isTransient ( field , jsonConfig ) ; } catch ( Exception e ) { log . info ( "<STR_LIT>" + beanClass + "<STR_LIT:.>" + name + "<STR_LIT>" , e ) ; } return false ; } private static boolean isTransient ( AnnotatedElement element , JsonConfig jsonConfig ) { for ( Iterator annotations = jsonConfig . getIgnoreFieldAnnotations ( ) . iterator ( ) ; annotations . hasNext ( ) ; ) { try { String annotationClassName = ( String ) annotations . next ( ) ; if ( element . getAnnotation ( ( Class ) Class . forName ( annotationClassName ) ) != null ) return true ; } catch ( Exception e ) { log . info ( "<STR_LIT>" + element + "<STR_LIT>" , e ) ; } } return false ; } private static Object morphPropertyValue ( String key , Object value , Class type , Class targetType ) { Morpher morpher = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( targetType ) ; if ( IdentityObjectMorpher . getInstance ( ) . equals ( morpher ) ) { log . warn ( "<STR_LIT>" + key + "<STR_LIT>" + type . getName ( ) + "<STR_LIT>" + targetType . getName ( ) + "<STR_LIT>" ) ; if ( Enum . class . isAssignableFrom ( targetType ) ) { JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new EnumMorpher ( targetType ) ) ; } else { JSONUtils . getMorpherRegistry ( ) . registerMorpher ( new BeanMorpher ( targetType , JSONUtils . getMorpherRegistry ( ) ) ) ; } } value = JSONUtils . getMorpherRegistry ( ) . morph ( targetType , value ) ; return value ; } private static void setProperty ( Object bean , String key , Object value , JsonConfig jsonConfig ) throws Exception { PropertySetStrategy propertySetStrategy = jsonConfig . getPropertySetStrategy ( ) != null ? jsonConfig . getPropertySetStrategy ( ) : PropertySetStrategy . DEFAULT ; propertySetStrategy . setProperty ( bean , key , value , jsonConfig ) ; } private static void setValue ( JSONObject jsonObject , String key , Object value , Class type , JsonConfig jsonConfig , boolean bypass ) { boolean accumulated = false ; if ( value == null ) { value = jsonConfig . findDefaultValueProcessor ( type ) . getDefaultValue ( type ) ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } if ( jsonObject . properties . containsKey ( key ) ) { if ( String . class . isAssignableFrom ( type ) ) { Object o = jsonObject . opt ( key ) ; if ( o instanceof JSONArray ) { ( ( JSONArray ) o ) . addString ( ( String ) value ) ; } else { jsonObject . properties . put ( key , new JSONArray ( ) . element ( o ) . addString ( ( String ) value ) ) ; } } else { jsonObject . accumulate ( key , value , jsonConfig ) ; } accumulated = true ; } else { if ( bypass || String . class . isAssignableFrom ( type ) ) { jsonObject . properties . put ( key , value ) ; } else { jsonObject . setInternal ( key , value , jsonConfig ) ; } } value = jsonObject . opt ( key ) ; if ( accumulated ) { JSONArray array = ( JSONArray ) value ; value = array . get ( array . size ( ) - <NUM_LIT:1> ) ; } firePropertySetEvent ( key , value , accumulated , jsonConfig ) ; } private boolean nullObject ; private Map properties ; public JSONObject ( ) { this . properties = new ListOrderedMap ( ) ; } public JSONObject ( boolean isNull ) { this ( ) ; this . nullObject = isNull ; } public JSONObject accumulate ( String key , boolean value ) { return _accumulate ( key , value ? Boolean . TRUE : Boolean . FALSE , new JsonConfig ( ) ) ; } public JSONObject accumulate ( String key , double value ) { return _accumulate ( key , Double . valueOf ( value ) , new JsonConfig ( ) ) ; } public JSONObject accumulate ( String key , int value ) { return _accumulate ( key , Integer . valueOf ( value ) , new JsonConfig ( ) ) ; } public JSONObject accumulate ( String key , long value ) { return _accumulate ( key , Long . valueOf ( value ) , new JsonConfig ( ) ) ; } public JSONObject accumulate ( String key , Object value ) { return _accumulate ( key , value , new JsonConfig ( ) ) ; } public JSONObject accumulate ( String key , Object value , JsonConfig jsonConfig ) { return _accumulate ( key , value , jsonConfig ) ; } public void accumulateAll ( Map map ) { accumulateAll ( map , new JsonConfig ( ) ) ; } public void accumulateAll ( Map map , JsonConfig jsonConfig ) { if ( map instanceof JSONObject ) { for ( Iterator entries = map . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; accumulate ( key , value , jsonConfig ) ; } } else { for ( Iterator entries = map . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String key = String . valueOf ( entry . getKey ( ) ) ; Object value = entry . getValue ( ) ; accumulate ( key , value , jsonConfig ) ; } } } public void clear ( ) { properties . clear ( ) ; } public int compareTo ( Object obj ) { if ( obj != null && ( obj instanceof JSONObject ) ) { JSONObject other = ( JSONObject ) obj ; int size1 = size ( ) ; int size2 = other . size ( ) ; if ( size1 < size2 ) { return - <NUM_LIT:1> ; } else if ( size1 > size2 ) { return <NUM_LIT:1> ; } else if ( this . equals ( other ) ) { return <NUM_LIT:0> ; } } return - <NUM_LIT:1> ; } public boolean containsKey ( Object key ) { return properties . containsKey ( key ) ; } public boolean containsValue ( Object value ) { return containsValue ( value , new JsonConfig ( ) ) ; } public boolean containsValue ( Object value , JsonConfig jsonConfig ) { try { value = processValue ( value , jsonConfig ) ; } catch ( JSONException e ) { return false ; } return properties . containsValue ( value ) ; } public JSONObject discard ( String key ) { verifyIsNull ( ) ; this . properties . remove ( key ) ; return this ; } public JSONObject element ( String key , boolean value ) { verifyIsNull ( ) ; return element ( key , value ? Boolean . TRUE : Boolean . FALSE ) ; } public JSONObject element ( String key , Collection value ) { return element ( key , value , new JsonConfig ( ) ) ; } public JSONObject element ( String key , Collection value , JsonConfig jsonConfig ) { if ( ! ( value instanceof JSONArray ) ) { value = JSONArray . fromObject ( value , jsonConfig ) ; } return setInternal ( key , value , jsonConfig ) ; } public JSONObject element ( String key , double value ) { verifyIsNull ( ) ; Double d = new Double ( value ) ; JSONUtils . testValidity ( d ) ; return element ( key , d ) ; } public JSONObject element ( String key , int value ) { verifyIsNull ( ) ; return element ( key , new Integer ( value ) ) ; } public JSONObject element ( String key , long value ) { verifyIsNull ( ) ; return element ( key , new Long ( value ) ) ; } public JSONObject element ( String key , Map value ) { return element ( key , value , new JsonConfig ( ) ) ; } public JSONObject element ( String key , Map value , JsonConfig jsonConfig ) { verifyIsNull ( ) ; if ( value instanceof JSONObject ) { return setInternal ( key , value , jsonConfig ) ; } else { return element ( key , JSONObject . fromObject ( value , jsonConfig ) , jsonConfig ) ; } } public JSONObject element ( String key , Object value ) { return element ( key , value , new JsonConfig ( ) ) ; } public JSONObject element ( String key , Object value , JsonConfig jsonConfig ) { verifyIsNull ( ) ; if ( key == null ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( value != null ) { value = processValue ( key , value , jsonConfig ) ; _setInternal ( key , value , jsonConfig ) ; } else { remove ( key ) ; } return this ; } public JSONObject elementOpt ( String key , Object value ) { return elementOpt ( key , value , new JsonConfig ( ) ) ; } public JSONObject elementOpt ( String key , Object value , JsonConfig jsonConfig ) { verifyIsNull ( ) ; if ( key != null && value != null ) { element ( key , value , jsonConfig ) ; } return this ; } public Set entrySet ( ) { return Collections . unmodifiableSet ( properties . entrySet ( ) ) ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! ( obj instanceof JSONObject ) ) { return false ; } JSONObject other = ( JSONObject ) obj ; if ( isNullObject ( ) ) { if ( other . isNullObject ( ) ) { return true ; } else { return false ; } } else { if ( other . isNullObject ( ) ) { return false ; } } if ( other . size ( ) != size ( ) ) { return false ; } for ( Iterator keys = properties . keySet ( ) . iterator ( ) ; keys . hasNext ( ) ; ) { String key = ( String ) keys . next ( ) ; if ( ! other . properties . containsKey ( key ) ) { return false ; } Object o1 = properties . get ( key ) ; Object o2 = other . properties . get ( key ) ; if ( JSONNull . getInstance ( ) . equals ( o1 ) ) { if ( JSONNull . getInstance ( ) . equals ( o2 ) ) { continue ; } else { return false ; } } else { if ( JSONNull . getInstance ( ) . equals ( o2 ) ) { return false ; } } if ( o1 instanceof String && o2 instanceof JSONFunction ) { if ( ! o1 . equals ( String . valueOf ( o2 ) ) ) { return false ; } } else if ( o1 instanceof JSONFunction && o2 instanceof String ) { if ( ! o2 . equals ( String . valueOf ( o1 ) ) ) { return false ; } } else if ( o1 instanceof JSONObject && o2 instanceof JSONObject ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else if ( o1 instanceof JSONArray && o2 instanceof JSONArray ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else if ( o1 instanceof JSONFunction && o2 instanceof JSONFunction ) { if ( ! o1 . equals ( o2 ) ) { return false ; } } else { if ( o1 instanceof String ) { if ( ! o1 . equals ( String . valueOf ( o2 ) ) ) { return false ; } } else if ( o2 instanceof String ) { if ( ! o2 . equals ( String . valueOf ( o1 ) ) ) { return false ; } } else { Morpher m1 = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( o1 . getClass ( ) ) ; Morpher m2 = JSONUtils . getMorpherRegistry ( ) . getMorpherFor ( o2 . getClass ( ) ) ; if ( m1 != null && m1 != IdentityObjectMorpher . getInstance ( ) ) { if ( ! o1 . equals ( JSONUtils . getMorpherRegistry ( ) . morph ( o1 . getClass ( ) , o2 ) ) ) { return false ; } } else if ( m2 != null && m2 != IdentityObjectMorpher . getInstance ( ) ) { if ( ! JSONUtils . getMorpherRegistry ( ) . morph ( o1 . getClass ( ) , o1 ) . equals ( o2 ) ) { return false ; } } else { if ( ! o1 . equals ( o2 ) ) { return false ; } } } } } return true ; } public Object get ( Object key ) { if ( key instanceof String ) { return get ( ( String ) key ) ; } return null ; } public Object get ( String key ) { verifyIsNull ( ) ; return this . properties . get ( key ) ; } public boolean getBoolean ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null ) { if ( o . equals ( Boolean . FALSE ) || ( o instanceof String && ( ( String ) o ) . equalsIgnoreCase ( "<STR_LIT:false>" ) ) ) { return false ; } else if ( o . equals ( Boolean . TRUE ) || ( o instanceof String && ( ( String ) o ) . equalsIgnoreCase ( "<STR_LIT:true>" ) ) ) { return true ; } } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public double getDouble ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null ) { try { return o instanceof Number ? ( ( Number ) o ) . doubleValue ( ) : Double . parseDouble ( ( String ) o ) ; } catch ( Exception e ) { throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public int getInt ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null ) { return o instanceof Number ? ( ( Number ) o ) . intValue ( ) : ( int ) getDouble ( key ) ; } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public JSONArray getJSONArray ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null && o instanceof JSONArray ) { return ( JSONArray ) o ; } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public JSONObject getJSONObject ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( JSONNull . getInstance ( ) . equals ( o ) ) { return new JSONObject ( true ) ; } else if ( o instanceof JSONObject ) { return ( JSONObject ) o ; } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public long getLong ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null ) { return o instanceof Number ? ( ( Number ) o ) . longValue ( ) : ( long ) getDouble ( key ) ; } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public String getString ( String key ) { verifyIsNull ( ) ; Object o = get ( key ) ; if ( o != null ) { return o . toString ( ) ; } throw new JSONException ( "<STR_LIT>" + JSONUtils . quote ( key ) + "<STR_LIT>" ) ; } public boolean has ( String key ) { verifyIsNull ( ) ; return this . properties . containsKey ( key ) ; } public int hashCode ( ) { int hashcode = <NUM_LIT> ; if ( isNullObject ( ) ) { return hashcode + JSONNull . getInstance ( ) . hashCode ( ) ; } for ( Iterator entries = properties . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; Object key = entry . getKey ( ) ; Object value = entry . getValue ( ) ; hashcode += key . hashCode ( ) + JSONUtils . hashCode ( value ) ; } return hashcode ; } public boolean isArray ( ) { return false ; } public boolean isEmpty ( ) { return this . properties . isEmpty ( ) ; } public boolean isNullObject ( ) { return nullObject ; } public Iterator keys ( ) { verifyIsNull ( ) ; return keySet ( ) . iterator ( ) ; } public Set keySet ( ) { return Collections . unmodifiableSet ( properties . keySet ( ) ) ; } public JSONArray names ( ) { verifyIsNull ( ) ; JSONArray ja = new JSONArray ( ) ; Iterator keys = keys ( ) ; while ( keys . hasNext ( ) ) { ja . element ( keys . next ( ) ) ; } return ja ; } public JSONArray names ( JsonConfig jsonConfig ) { verifyIsNull ( ) ; JSONArray ja = new JSONArray ( ) ; Iterator keys = keys ( ) ; while ( keys . hasNext ( ) ) { ja . element ( keys . next ( ) , jsonConfig ) ; } return ja ; } public Object opt ( String key ) { verifyIsNull ( ) ; return key == null ? null : this . properties . get ( key ) ; } public boolean optBoolean ( String key ) { verifyIsNull ( ) ; return optBoolean ( key , false ) ; } public boolean optBoolean ( String key , boolean defaultValue ) { verifyIsNull ( ) ; try { return getBoolean ( key ) ; } catch ( Exception e ) { return defaultValue ; } } public double optDouble ( String key ) { verifyIsNull ( ) ; return optDouble ( key , Double . NaN ) ; } public double optDouble ( String key , double defaultValue ) { verifyIsNull ( ) ; try { Object o = opt ( key ) ; return o instanceof Number ? ( ( Number ) o ) . doubleValue ( ) : new Double ( ( String ) o ) . doubleValue ( ) ; } catch ( Exception e ) { return defaultValue ; } } public int optInt ( String key ) { verifyIsNull ( ) ; return optInt ( key , <NUM_LIT:0> ) ; } public int optInt ( String key , int defaultValue ) { verifyIsNull ( ) ; try { return getInt ( key ) ; } catch ( Exception e ) { return defaultValue ; } } public JSONArray optJSONArray ( String key ) { verifyIsNull ( ) ; Object o = opt ( key ) ; return o instanceof JSONArray ? ( JSONArray ) o : null ; } public JSONObject optJSONObject ( String key ) { verifyIsNull ( ) ; Object o = opt ( key ) ; return o instanceof JSONObject ? ( JSONObject ) o : null ; } public long optLong ( String key ) { verifyIsNull ( ) ; return optLong ( key , <NUM_LIT:0> ) ; } public long optLong ( String key , long defaultValue ) { verifyIsNull ( ) ; try { return getLong ( key ) ; } catch ( Exception e ) { return defaultValue ; } } public String optString ( String key ) { verifyIsNull ( ) ; return optString ( key , "<STR_LIT>" ) ; } public String optString ( String key , String defaultValue ) { verifyIsNull ( ) ; Object o = opt ( key ) ; return o != null ? o . toString ( ) : defaultValue ; } public Object put ( String key , Object value ) { if ( key == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Object previous = properties . get ( key ) ; element ( String . valueOf ( key ) , value ) ; return previous ; } public void putAll ( Map map ) { putAll ( map , new JsonConfig ( ) ) ; } public void putAll ( Map map , JsonConfig jsonConfig ) { if ( map instanceof JSONObject ) { for ( Iterator entries = map . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; this . properties . put ( key , value ) ; } } else { for ( Iterator entries = map . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String key = String . valueOf ( entry . getKey ( ) ) ; Object value = entry . getValue ( ) ; element ( key , value , jsonConfig ) ; } } } public Object remove ( Object key ) { return properties . remove ( key ) ; } public Object remove ( String key ) { verifyIsNull ( ) ; return this . properties . remove ( key ) ; } public int size ( ) { return this . properties . size ( ) ; } public JSONArray toJSONArray ( JSONArray names ) { verifyIsNull ( ) ; if ( names == null || names . size ( ) == <NUM_LIT:0> ) { return null ; } JSONArray ja = new JSONArray ( ) ; for ( int i = <NUM_LIT:0> ; i < names . size ( ) ; i += <NUM_LIT:1> ) { ja . element ( this . opt ( names . getString ( i ) ) ) ; } return ja ; } public String toString ( ) { if ( isNullObject ( ) ) { return JSONNull . getInstance ( ) . toString ( ) ; } try { Iterator keys = keys ( ) ; StringBuffer sb = new StringBuffer ( "<STR_LIT:{>" ) ; while ( keys . hasNext ( ) ) { if ( sb . length ( ) > <NUM_LIT:1> ) { sb . append ( '<CHAR_LIT:U+002C>' ) ; } Object o = keys . next ( ) ; sb . append ( JSONUtils . quote ( o . toString ( ) ) ) ; sb . append ( '<CHAR_LIT::>' ) ; sb . append ( JSONUtils . valueToString ( this . properties . get ( o ) ) ) ; } sb . append ( '<CHAR_LIT:}>' ) ; return sb . toString ( ) ; } catch ( Exception e ) { return null ; } } public String toString ( int indentFactor ) { if ( isNullObject ( ) ) { return JSONNull . getInstance ( ) . toString ( ) ; } if ( indentFactor == <NUM_LIT:0> ) { return this . toString ( ) ; } return toString ( indentFactor , <NUM_LIT:0> ) ; } public String toString ( int indentFactor , int indent ) { if ( isNullObject ( ) ) { return JSONNull . getInstance ( ) . toString ( ) ; } int i ; int n = size ( ) ; if ( n == <NUM_LIT:0> ) { return "<STR_LIT:{}>" ; } if ( indentFactor == <NUM_LIT:0> ) { return this . toString ( ) ; } Iterator keys = keys ( ) ; StringBuffer sb = new StringBuffer ( "<STR_LIT:{>" ) ; int newindent = indent + indentFactor ; Object o ; if ( n == <NUM_LIT:1> ) { o = keys . next ( ) ; sb . append ( JSONUtils . quote ( o . toString ( ) ) ) ; sb . append ( "<STR_LIT::U+0020>" ) ; sb . append ( JSONUtils . valueToString ( this . properties . get ( o ) , indentFactor , indent ) ) ; } else { while ( keys . hasNext ( ) ) { o = keys . next ( ) ; if ( sb . length ( ) > <NUM_LIT:1> ) { sb . append ( "<STR_LIT>" ) ; } else { sb . append ( '<STR_LIT:\n>' ) ; } for ( i = <NUM_LIT:0> ; i < newindent ; i += <NUM_LIT:1> ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } sb . append ( JSONUtils . quote ( o . toString ( ) ) ) ; sb . append ( "<STR_LIT::U+0020>" ) ; sb . append ( JSONUtils . valueToString ( this . properties . get ( o ) , indentFactor , newindent ) ) ; } if ( sb . length ( ) > <NUM_LIT:1> ) { sb . append ( '<STR_LIT:\n>' ) ; for ( i = <NUM_LIT:0> ; i < indent ; i += <NUM_LIT:1> ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } } for ( i = <NUM_LIT:0> ; i < indent ; i += <NUM_LIT:1> ) { sb . insert ( <NUM_LIT:0> , '<CHAR_LIT:U+0020>' ) ; } } sb . append ( '<CHAR_LIT:}>' ) ; return sb . toString ( ) ; } public Collection values ( ) { return Collections . unmodifiableCollection ( properties . values ( ) ) ; } protected void write ( Writer writer , WritingVisitor visitor ) throws IOException { try { if ( isNullObject ( ) ) { writer . write ( JSONNull . getInstance ( ) . toString ( ) ) ; } boolean b = false ; Iterator keys = visitor . keySet ( this ) . iterator ( ) ; writer . write ( '<CHAR_LIT>' ) ; while ( keys . hasNext ( ) ) { if ( b ) { writer . write ( '<CHAR_LIT:U+002C>' ) ; } Object k = keys . next ( ) ; writer . write ( JSONUtils . quote ( k . toString ( ) ) ) ; writer . write ( '<CHAR_LIT::>' ) ; Object v = this . properties . get ( k ) ; if ( v instanceof JSON ) { visitor . on ( ( JSON ) v , writer ) ; } else { visitor . on ( v , writer ) ; } b = true ; } writer . write ( '<CHAR_LIT:}>' ) ; } catch ( IOException e ) { throw new JSONException ( e ) ; } } private JSONObject _accumulate ( String key , Object value , JsonConfig jsonConfig ) { if ( isNullObject ( ) ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( ! has ( key ) ) { setInternal ( key , value , jsonConfig ) ; } else { Object o = opt ( key ) ; if ( o instanceof JSONArray ) { ( ( JSONArray ) o ) . element ( value , jsonConfig ) ; } else { setInternal ( key , new JSONArray ( ) . element ( o ) . element ( value , jsonConfig ) , jsonConfig ) ; } } return this ; } protected Object _processValue ( Object value , JsonConfig jsonConfig ) { if ( value instanceof JSONTokener ) { return _fromJSONTokener ( ( JSONTokener ) value , jsonConfig ) ; } else if ( value != null && Enum . class . isAssignableFrom ( value . getClass ( ) ) ) { return ( ( Enum ) value ) . name ( ) ; } return super . _processValue ( value , jsonConfig ) ; } private JSONObject _setInternal ( String key , Object value , JsonConfig jsonConfig ) { verifyIsNull ( ) ; if ( key == null ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( JSONUtils . isString ( value ) && JSONUtils . mayBeJSON ( String . valueOf ( value ) ) ) { this . properties . put ( key , value ) ; } else { if ( CycleDetectionStrategy . IGNORE_PROPERTY_OBJ == value || CycleDetectionStrategy . IGNORE_PROPERTY_ARR == value ) { } else { this . properties . put ( key , value ) ; } } return this ; } private Object processValue ( Object value , JsonConfig jsonConfig ) { if ( value != null ) { JsonValueProcessor processor = jsonConfig . findJsonValueProcessor ( value . getClass ( ) ) ; if ( processor != null ) { value = processor . processObjectValue ( null , value , jsonConfig ) ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } } return _processValue ( value , jsonConfig ) ; } private Object processValue ( String key , Object value , JsonConfig jsonConfig ) { if ( value != null ) { JsonValueProcessor processor = jsonConfig . findJsonValueProcessor ( value . getClass ( ) , key ) ; if ( processor != null ) { value = processor . processObjectValue ( null , value , jsonConfig ) ; if ( ! JsonVerifier . isValidJsonValue ( value ) ) { throw new JSONException ( "<STR_LIT>" + value ) ; } } } return _processValue ( value , jsonConfig ) ; } private JSONObject setInternal ( String key , Object value , JsonConfig jsonConfig ) { return _setInternal ( key , processValue ( key , value , jsonConfig ) , jsonConfig ) ; } private void verifyIsNull ( ) { if ( isNullObject ( ) ) { throw new JSONException ( "<STR_LIT>" ) ; } } } </s>
<s> package net . sf . json . util ; import net . sf . ezmorph . ObjectMorpher ; public class EnumMorpher implements ObjectMorpher { private Class enumClass ; public EnumMorpher ( Class enumClass ) { if ( enumClass == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( ! Enum . class . isAssignableFrom ( enumClass ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . enumClass = enumClass ; } public Object morph ( Object value ) { if ( value == null ) { return enumClass . cast ( null ) ; } return Enum . valueOf ( enumClass , String . valueOf ( value ) ) ; } public Class morphsTo ( ) { return enumClass ; } public boolean supports ( Class clazz ) { return String . class . isAssignableFrom ( clazz ) ; } } </s>
<s> package net . sf . json . regexp ; import org . apache . commons . lang . exception . NestableRuntimeException ; import org . apache . oro . text . regex . MalformedPatternException ; import org . apache . oro . text . regex . Pattern ; import org . apache . oro . text . regex . PatternMatcher ; import org . apache . oro . text . regex . Perl5Compiler ; import org . apache . oro . text . regex . Perl5Matcher ; public class Perl5RegexpMatcher implements RegexpMatcher { private static final Perl5Compiler compiler = new Perl5Compiler ( ) ; private Pattern pattern ; public Perl5RegexpMatcher ( String pattern ) { this ( pattern , false ) ; } public Perl5RegexpMatcher ( String pattern , boolean multiline ) { try { if ( multiline ) { this . pattern = compiler . compile ( pattern , Perl5Compiler . READ_ONLY_MASK | Perl5Compiler . MULTILINE_MASK ) ; } else { this . pattern = compiler . compile ( pattern , Perl5Compiler . READ_ONLY_MASK ) ; } } catch ( MalformedPatternException mpe ) { throw new NestableRuntimeException ( mpe ) ; } } public String getGroupIfMatches ( String str , int group ) { PatternMatcher matcher = new Perl5Matcher ( ) ; if ( matcher . matches ( str , pattern ) ) { return matcher . getMatch ( ) . group ( <NUM_LIT:1> ) ; } return "<STR_LIT>" ; } public boolean matches ( String str ) { return new Perl5Matcher ( ) . matches ( str , pattern ) ; } } </s>
<s> package net . sf . json . regexp ; public interface RegexpMatcher { String getGroupIfMatches ( String str , int group ) ; boolean matches ( String str ) ; } </s>
<s> package net . sf . json . regexp ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class JdkRegexpMatcher implements RegexpMatcher { private final Pattern pattern ; public JdkRegexpMatcher ( String pattern ) { this ( pattern , false ) ; } public JdkRegexpMatcher ( String pattern , boolean multiline ) { if ( multiline ) { this . pattern = Pattern . compile ( pattern , Pattern . MULTILINE ) ; } else { this . pattern = Pattern . compile ( pattern ) ; } } public String getGroupIfMatches ( String str , int group ) { Matcher matcher = pattern . matcher ( str ) ; if ( matcher . matches ( ) ) { return matcher . group ( group ) ; } return "<STR_LIT>" ; } public boolean matches ( String str ) { return pattern . matcher ( str ) . matches ( ) ; } } </s>
<s> package net . sf . json . regexp ; public class RegexpUtils { private static String javaVersion = "<STR_LIT>" ; static { javaVersion = System . getProperty ( "<STR_LIT>" ) ; } public static RegexpMatcher getMatcher ( String pattern ) { if ( isJDK13 ( ) ) { return new Perl5RegexpMatcher ( pattern ) ; } else { return new JdkRegexpMatcher ( pattern ) ; } } public static RegexpMatcher getMatcher ( String pattern , boolean multiline ) { if ( isJDK13 ( ) ) { return new Perl5RegexpMatcher ( pattern , true ) ; } else { return new JdkRegexpMatcher ( pattern , true ) ; } } public static boolean isJDK13 ( ) { return javaVersion . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ; } private RegexpUtils ( ) { } } </s>
<s> package net . sf . json . groovy ; import groovy . lang . Closure ; import groovy . lang . GString ; import groovy . lang . GroovyObjectSupport ; import groovy . lang . MissingMethodException ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Stack ; import net . sf . json . JSON ; import net . sf . json . JSONArray ; import net . sf . json . JSONException ; import net . sf . json . JSONObject ; import net . sf . json . JSONSerializer ; public class JsonGroovyBuilder extends GroovyObjectSupport { private static final String JSON = "<STR_LIT>" ; private JSON current ; private Map properties ; private Stack stack ; public JsonGroovyBuilder ( ) { stack = new Stack ( ) ; properties = new HashMap ( ) ; } public Object getProperty ( String name ) { if ( ! stack . isEmpty ( ) ) { Object top = stack . peek ( ) ; if ( top instanceof JSONObject ) { JSONObject json = ( JSONObject ) top ; if ( json . containsKey ( name ) ) { return json . get ( name ) ; } else { return _getProperty ( name ) ; } } else { return _getProperty ( name ) ; } } else { return _getProperty ( name ) ; } } public Object invokeMethod ( String name , Object arg ) { if ( JSON . equals ( name ) && stack . isEmpty ( ) ) { return createObject ( name , arg ) ; } Object [ ] args = ( Object [ ] ) arg ; if ( args . length == <NUM_LIT:0> ) { throw new MissingMethodException ( name , getClass ( ) , args ) ; } Object value = null ; if ( args . length > <NUM_LIT:1> ) { JSONArray array = new JSONArray ( ) ; stack . push ( array ) ; for ( int i = <NUM_LIT:0> ; i < args . length ; i ++ ) { if ( args [ i ] instanceof Closure ) { append ( name , createObject ( ( Closure ) args [ i ] ) ) ; } else if ( args [ i ] instanceof Map ) { append ( name , createObject ( ( Map ) args [ i ] ) ) ; } else if ( args [ i ] instanceof List ) { append ( name , createArray ( ( List ) args [ i ] ) ) ; } else { _append ( name , args [ i ] , ( JSON ) stack . peek ( ) ) ; } } stack . pop ( ) ; } else { if ( args [ <NUM_LIT:0> ] instanceof Closure ) { value = createObject ( ( Closure ) args [ <NUM_LIT:0> ] ) ; } else if ( args [ <NUM_LIT:0> ] instanceof Map ) { value = createObject ( ( Map ) args [ <NUM_LIT:0> ] ) ; } else if ( args [ <NUM_LIT:0> ] instanceof List ) { value = createArray ( ( List ) args [ <NUM_LIT:0> ] ) ; } } if ( stack . isEmpty ( ) ) { JSONObject object = new JSONObject ( ) ; object . accumulate ( name , current ) ; current = object ; } else { JSON top = ( JSON ) stack . peek ( ) ; if ( top instanceof JSONObject ) { append ( name , current == null ? value : current ) ; } } return current ; } public void setProperty ( String name , Object value ) { if ( value instanceof GString ) { value = value . toString ( ) ; try { value = JSONSerializer . toJSON ( value ) ; } catch ( JSONException jsone ) { } } else if ( value instanceof Closure ) { value = createObject ( ( Closure ) value ) ; } else if ( value instanceof Map ) { value = createObject ( ( Map ) value ) ; } else if ( value instanceof List ) { value = createArray ( ( List ) value ) ; } append ( name , value ) ; } private Object _getProperty ( String name ) { if ( properties . containsKey ( name ) ) { return properties . get ( name ) ; } else { return super . getProperty ( name ) ; } } private void append ( String key , Object value ) { Object target = null ; if ( ! stack . isEmpty ( ) ) { target = stack . peek ( ) ; current = ( JSON ) target ; _append ( key , value , current ) ; } else { properties . put ( key , value ) ; } } private void _append ( String key , Object value , JSON target ) { if ( target instanceof JSONObject ) { ( ( JSONObject ) target ) . accumulate ( key , value ) ; } else if ( target instanceof JSONArray ) { ( ( JSONArray ) target ) . element ( value ) ; } } private JSON createArray ( List list ) { JSONArray array = new JSONArray ( ) ; stack . push ( array ) ; for ( Iterator elements = list . iterator ( ) ; elements . hasNext ( ) ; ) { Object element = elements . next ( ) ; if ( element instanceof Closure ) { element = createObject ( ( Closure ) element ) ; } else if ( element instanceof Map ) { element = createObject ( ( Map ) element ) ; } else if ( element instanceof List ) { element = createArray ( ( List ) element ) ; } array . element ( element ) ; } stack . pop ( ) ; return array ; } private JSON createObject ( Closure closure ) { JSONObject object = new JSONObject ( ) ; stack . push ( object ) ; closure . setDelegate ( this ) ; closure . setResolveStrategy ( Closure . DELEGATE_FIRST ) ; closure . call ( ) ; stack . pop ( ) ; return object ; } private JSON createObject ( Map map ) { JSONObject object = new JSONObject ( ) ; stack . push ( object ) ; for ( Iterator properties = map . entrySet ( ) . iterator ( ) ; properties . hasNext ( ) ; ) { Map . Entry property = ( Map . Entry ) properties . next ( ) ; String key = String . valueOf ( property . getKey ( ) ) ; Object value = property . getValue ( ) ; if ( value instanceof Closure ) { value = createObject ( ( Closure ) value ) ; } else if ( value instanceof Map ) { value = createObject ( ( Map ) value ) ; } else if ( value instanceof List ) { value = createArray ( ( List ) value ) ; } object . element ( key , value ) ; } stack . pop ( ) ; return object ; } private JSON createObject ( String name , Object arg ) { Object [ ] args = ( Object [ ] ) arg ; if ( args . length == <NUM_LIT:0> ) { throw new MissingMethodException ( name , getClass ( ) , args ) ; } if ( args . length == <NUM_LIT:1> ) { if ( args [ <NUM_LIT:0> ] instanceof Closure ) { return createObject ( ( Closure ) args [ <NUM_LIT:0> ] ) ; } else if ( args [ <NUM_LIT:0> ] instanceof Map ) { return createObject ( ( Map ) args [ <NUM_LIT:0> ] ) ; } else if ( args [ <NUM_LIT:0> ] instanceof List ) { return createArray ( ( List ) args [ <NUM_LIT:0> ] ) ; } else { throw new JSONException ( "<STR_LIT>" ) ; } } else { JSONArray array = new JSONArray ( ) ; stack . push ( array ) ; for ( int i = <NUM_LIT:0> ; i < args . length ; i ++ ) { if ( args [ i ] instanceof Closure ) { append ( name , createObject ( ( Closure ) args [ i ] ) ) ; } else if ( args [ i ] instanceof Map ) { append ( name , createObject ( ( Map ) args [ i ] ) ) ; } else if ( args [ i ] instanceof List ) { append ( name , createArray ( ( List ) args [ i ] ) ) ; } else { _append ( name , args [ i ] , ( JSON ) stack . peek ( ) ) ; } } stack . pop ( ) ; return array ; } } } </s>
<s> package net . sf . json . groovy ; import groovy . lang . GroovyObjectSupport ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . Reader ; import java . net . URL ; import net . sf . json . JSON ; import net . sf . json . JSONSerializer ; import net . sf . json . JsonConfig ; public class JsonSlurper extends GroovyObjectSupport { private JsonConfig jsonConfig ; public JsonSlurper ( ) { this ( new JsonConfig ( ) ) ; } public JsonSlurper ( JsonConfig jsonConfig ) { this . jsonConfig = jsonConfig != null ? jsonConfig : new JsonConfig ( ) ; } public JSON parse ( File file ) throws IOException { return parse ( new FileReader ( file ) ) ; } public JSON parse ( URL url ) throws IOException { return parse ( url . openConnection ( ) . getInputStream ( ) ) ; } public JSON parse ( InputStream input ) throws IOException { return parse ( new InputStreamReader ( input ) ) ; } public JSON parse ( String uri ) throws IOException { return parse ( new URL ( uri ) ) ; } public JSON parse ( Reader reader ) throws IOException { StringBuffer buffer = new StringBuffer ( ) ; BufferedReader in = new BufferedReader ( reader ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { buffer . append ( line ) . append ( "<STR_LIT:n>" ) ; } return parseText ( buffer . toString ( ) ) ; } public JSON parseText ( String text ) { return JSONSerializer . toJSON ( text , jsonConfig ) ; } } </s>
<s> package net . sf . json . xml ; public interface JSONTypes { String ARRAY = "<STR_LIT>" ; String BOOLEAN = "<STR_LIT:boolean>" ; String FLOAT = "<STR_LIT:float>" ; String FUNCTION = "<STR_LIT>" ; String INTEGER = "<STR_LIT>" ; String NUMBER = "<STR_LIT:number>" ; String OBJECT = "<STR_LIT>" ; String STRING = "<STR_LIT:string>" ; } </s>
<s> package net . sf . json . xml ; import java . io . BufferedReader ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . StringReader ; import java . io . UnsupportedEncodingException ; import java . util . Arrays ; import java . util . Iterator ; import java . util . Map ; import java . util . TreeMap ; import net . sf . json . JSON ; import net . sf . json . JSONArray ; import net . sf . json . JSONException ; import net . sf . json . JSONFunction ; import net . sf . json . JSONNull ; import net . sf . json . JSONObject ; import net . sf . json . util . JSONUtils ; import nu . xom . Attribute ; import nu . xom . Builder ; import nu . xom . Document ; import nu . xom . Element ; import nu . xom . Elements ; import nu . xom . Node ; import nu . xom . Serializer ; import nu . xom . Text ; import org . apache . commons . lang . ArrayUtils ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; public class XMLSerializer { private static final String [ ] EMPTY_ARRAY = new String [ <NUM_LIT:0> ] ; private static final String JSON_PREFIX = "<STR_LIT>" ; private static final Log log = LogFactory . getLog ( XMLSerializer . class ) ; private String arrayName ; private String elementName ; private String [ ] expandableProperties ; private boolean forceTopLevelObject ; private boolean namespaceLenient ; private Map namespacesPerElement = new TreeMap ( ) ; private String objectName ; private boolean removeNamespacePrefixFromElements ; private String rootName ; private Map rootNamespace = new TreeMap ( ) ; private boolean skipNamespaces ; private boolean skipWhitespace ; private boolean trimSpaces ; private boolean typeHintsCompatibility ; private boolean typeHintsEnabled ; public XMLSerializer ( ) { setObjectName ( "<STR_LIT>" ) ; setArrayName ( "<STR_LIT:a>" ) ; setElementName ( "<STR_LIT:e>" ) ; setTypeHintsEnabled ( true ) ; setTypeHintsCompatibility ( true ) ; setNamespaceLenient ( false ) ; setSkipNamespaces ( false ) ; setRemoveNamespacePrefixFromElements ( false ) ; setTrimSpaces ( false ) ; setExpandableProperties ( EMPTY_ARRAY ) ; setSkipNamespaces ( false ) ; } public void addNamespace ( String prefix , String uri ) { addNamespace ( prefix , uri , null ) ; } public void addNamespace ( String prefix , String uri , String elementName ) { if ( StringUtils . isBlank ( uri ) ) { return ; } if ( prefix == null ) { prefix = "<STR_LIT>" ; } if ( StringUtils . isBlank ( elementName ) ) { rootNamespace . put ( prefix . trim ( ) , uri . trim ( ) ) ; } else { Map nameSpaces = ( Map ) namespacesPerElement . get ( elementName ) ; if ( nameSpaces == null ) { nameSpaces = new TreeMap ( ) ; namespacesPerElement . put ( elementName , nameSpaces ) ; } nameSpaces . put ( prefix , uri ) ; } } public void clearNamespaces ( ) { rootNamespace . clear ( ) ; namespacesPerElement . clear ( ) ; } public void clearNamespaces ( String elementName ) { if ( StringUtils . isBlank ( elementName ) ) { rootNamespace . clear ( ) ; } else { namespacesPerElement . remove ( elementName ) ; } } public String getArrayName ( ) { return arrayName ; } public String getElementName ( ) { return elementName ; } public String [ ] getExpandableProperties ( ) { return expandableProperties ; } public String getObjectName ( ) { return objectName ; } public String getRootName ( ) { return rootName ; } public boolean isForceTopLevelObject ( ) { return forceTopLevelObject ; } public boolean isNamespaceLenient ( ) { return namespaceLenient ; } public boolean isRemoveNamespacePrefixFromElements ( ) { return removeNamespacePrefixFromElements ; } public boolean isSkipNamespaces ( ) { return skipNamespaces ; } public boolean isSkipWhitespace ( ) { return skipWhitespace ; } public boolean isTrimSpaces ( ) { return trimSpaces ; } public boolean isTypeHintsCompatibility ( ) { return typeHintsCompatibility ; } public boolean isTypeHintsEnabled ( ) { return typeHintsEnabled ; } public JSON read ( String xml ) { JSON json = null ; try { Document doc = new Builder ( ) . build ( new StringReader ( xml ) ) ; Element root = doc . getRootElement ( ) ; if ( isNullObject ( root ) ) { return JSONNull . getInstance ( ) ; } String defaultType = getType ( root , JSONTypes . STRING ) ; if ( isArray ( root , true ) ) { json = processArrayElement ( root , defaultType ) ; if ( forceTopLevelObject ) { String key = removeNamespacePrefix ( root . getQualifiedName ( ) ) ; json = new JSONObject ( ) . element ( key , json ) ; } } else { json = processObjectElement ( root , defaultType ) ; if ( forceTopLevelObject ) { String key = removeNamespacePrefix ( root . getQualifiedName ( ) ) ; json = new JSONObject ( ) . element ( key , json ) ; } } } catch ( JSONException jsone ) { throw jsone ; } catch ( Exception e ) { throw new JSONException ( e ) ; } return json ; } public JSON readFromFile ( File file ) { if ( file == null ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( ! file . canRead ( ) ) { throw new JSONException ( "<STR_LIT>" ) ; } if ( file . isDirectory ( ) ) { throw new JSONException ( "<STR_LIT>" ) ; } try { return readFromStream ( new FileInputStream ( file ) ) ; } catch ( IOException ioe ) { throw new JSONException ( ioe ) ; } } public JSON readFromFile ( String path ) { return readFromStream ( Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( path ) ) ; } public JSON readFromStream ( InputStream stream ) { try { StringBuffer xml = new StringBuffer ( ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( stream ) ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { xml . append ( line ) ; } return read ( xml . toString ( ) ) ; } catch ( IOException ioe ) { throw new JSONException ( ioe ) ; } } public void removeNamespace ( String prefix ) { removeNamespace ( prefix , null ) ; } public void removeNamespace ( String prefix , String elementName ) { if ( prefix == null ) { prefix = "<STR_LIT>" ; } if ( StringUtils . isBlank ( elementName ) ) { rootNamespace . remove ( prefix . trim ( ) ) ; } else { Map nameSpaces = ( Map ) namespacesPerElement . get ( elementName ) ; nameSpaces . remove ( prefix ) ; } } public void setArrayName ( String arrayName ) { this . arrayName = StringUtils . isBlank ( arrayName ) ? "<STR_LIT:a>" : arrayName ; } public void setElementName ( String elementName ) { this . elementName = StringUtils . isBlank ( elementName ) ? "<STR_LIT:e>" : elementName ; } public void setExpandableProperties ( String [ ] expandableProperties ) { this . expandableProperties = expandableProperties == null ? EMPTY_ARRAY : expandableProperties ; } public void setForceTopLevelObject ( boolean forceTopLevelObject ) { this . forceTopLevelObject = forceTopLevelObject ; } public void setNamespace ( String prefix , String uri ) { setNamespace ( prefix , uri , null ) ; } public void setNamespace ( String prefix , String uri , String elementName ) { if ( StringUtils . isBlank ( uri ) ) { return ; } if ( prefix == null ) { prefix = "<STR_LIT>" ; } if ( StringUtils . isBlank ( elementName ) ) { rootNamespace . clear ( ) ; rootNamespace . put ( prefix . trim ( ) , uri . trim ( ) ) ; } else { Map nameSpaces = ( Map ) namespacesPerElement . get ( elementName ) ; if ( nameSpaces == null ) { nameSpaces = new TreeMap ( ) ; namespacesPerElement . put ( elementName , nameSpaces ) ; } nameSpaces . clear ( ) ; nameSpaces . put ( prefix , uri ) ; } } public void setNamespaceLenient ( boolean namespaceLenient ) { this . namespaceLenient = namespaceLenient ; } public void setObjectName ( String objectName ) { this . objectName = StringUtils . isBlank ( objectName ) ? "<STR_LIT>" : objectName ; } public void setRemoveNamespacePrefixFromElements ( boolean removeNamespacePrefixFromElements ) { this . removeNamespacePrefixFromElements = removeNamespacePrefixFromElements ; } public void setRootName ( String rootName ) { this . rootName = StringUtils . isBlank ( rootName ) ? null : rootName ; } public void setSkipNamespaces ( boolean skipNamespaces ) { this . skipNamespaces = skipNamespaces ; } public void setSkipWhitespace ( boolean skipWhitespace ) { this . skipWhitespace = skipWhitespace ; } public void setTrimSpaces ( boolean trimSpaces ) { this . trimSpaces = trimSpaces ; } public void setTypeHintsCompatibility ( boolean typeHintsCompatibility ) { this . typeHintsCompatibility = typeHintsCompatibility ; } public void setTypeHintsEnabled ( boolean typeHintsEnabled ) { this . typeHintsEnabled = typeHintsEnabled ; } public String write ( JSON json ) { return write ( json , null ) ; } public String write ( JSON json , String encoding ) { if ( JSONNull . getInstance ( ) . equals ( json ) ) { Element root = null ; root = newElement ( getRootName ( ) == null ? getObjectName ( ) : getRootName ( ) ) ; root . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:null>" ) , "<STR_LIT:true>" ) ) ; Document doc = new Document ( root ) ; return writeDocument ( doc , encoding ) ; } else if ( json instanceof JSONArray ) { JSONArray jsonArray = ( JSONArray ) json ; Element root = processJSONArray ( jsonArray , newElement ( getRootName ( ) == null ? getArrayName ( ) : getRootName ( ) ) , expandableProperties ) ; Document doc = new Document ( root ) ; return writeDocument ( doc , encoding ) ; } else { JSONObject jsonObject = ( JSONObject ) json ; Element root = null ; if ( jsonObject . isNullObject ( ) ) { root = newElement ( getObjectName ( ) ) ; root . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:null>" ) , "<STR_LIT:true>" ) ) ; } else { root = processJSONObject ( jsonObject , newElement ( getRootName ( ) == null ? getObjectName ( ) : getRootName ( ) ) , expandableProperties , true ) ; } Document doc = new Document ( root ) ; return writeDocument ( doc , encoding ) ; } } private String addJsonPrefix ( String str ) { if ( ! isTypeHintsCompatibility ( ) ) { return JSON_PREFIX + str ; } return str ; } private void addNameSpaceToElement ( Element element ) { String elementName = null ; if ( element instanceof CustomElement ) { elementName = ( ( CustomElement ) element ) . getQName ( ) ; } else { elementName = element . getQualifiedName ( ) ; } Map nameSpaces = ( Map ) namespacesPerElement . get ( elementName ) ; if ( nameSpaces != null && ! nameSpaces . isEmpty ( ) ) { setNamespaceLenient ( true ) ; for ( Iterator entries = nameSpaces . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String prefix = ( String ) entry . getKey ( ) ; String uri = ( String ) entry . getValue ( ) ; if ( StringUtils . isBlank ( prefix ) ) { element . setNamespaceURI ( uri ) ; } else { element . addNamespaceDeclaration ( prefix , uri ) ; } } } } private boolean checkChildElements ( Element element , boolean isTopLevel ) { int childCount = element . getChildCount ( ) ; Elements elements = element . getChildElements ( ) ; int elementCount = elements . size ( ) ; if ( childCount == <NUM_LIT:1> && element . getChild ( <NUM_LIT:0> ) instanceof Text ) { return isTopLevel ; } if ( childCount == elementCount ) { if ( elementCount == <NUM_LIT:0> ) { return true ; } if ( elementCount == <NUM_LIT:1> ) { if ( skipWhitespace || element . getChild ( <NUM_LIT:0> ) instanceof Text ) { return true ; } else { return false ; } } } if ( childCount > elementCount ) { for ( int i = <NUM_LIT:0> ; i < childCount ; i ++ ) { Node node = element . getChild ( i ) ; if ( node instanceof Text ) { Text text = ( Text ) node ; if ( StringUtils . isNotBlank ( StringUtils . strip ( text . getValue ( ) ) ) && ! skipWhitespace ) { return false ; } } } } String childName = elements . get ( <NUM_LIT:0> ) . getQualifiedName ( ) ; for ( int i = <NUM_LIT:1> ; i < elementCount ; i ++ ) { if ( childName . compareTo ( elements . get ( i ) . getQualifiedName ( ) ) != <NUM_LIT:0> ) { return false ; } } return true ; } private String getClass ( Element element ) { Attribute attribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) ; String clazz = null ; if ( attribute != null ) { String clazzText = attribute . getValue ( ) . trim ( ) ; if ( JSONTypes . OBJECT . compareToIgnoreCase ( clazzText ) == <NUM_LIT:0> ) { clazz = JSONTypes . OBJECT ; } else if ( JSONTypes . ARRAY . compareToIgnoreCase ( clazzText ) == <NUM_LIT:0> ) { clazz = JSONTypes . ARRAY ; } } return clazz ; } private String getType ( Element element ) { return getType ( element , null ) ; } private String getType ( Element element , String defaultType ) { Attribute attribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) ; String type = null ; if ( attribute != null ) { String typeText = attribute . getValue ( ) . trim ( ) ; if ( JSONTypes . BOOLEAN . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . BOOLEAN ; } else if ( JSONTypes . NUMBER . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . NUMBER ; } else if ( JSONTypes . INTEGER . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . INTEGER ; } else if ( JSONTypes . FLOAT . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . FLOAT ; } else if ( JSONTypes . OBJECT . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . OBJECT ; } else if ( JSONTypes . ARRAY . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . ARRAY ; } else if ( JSONTypes . STRING . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . STRING ; } else if ( JSONTypes . FUNCTION . compareToIgnoreCase ( typeText ) == <NUM_LIT:0> ) { type = JSONTypes . FUNCTION ; } } else { if ( defaultType != null ) { log . info ( "<STR_LIT>" + defaultType ) ; type = defaultType ; } } return type ; } private boolean hasNamespaces ( Element element ) { int namespaces = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < element . getNamespaceDeclarationCount ( ) ; i ++ ) { String prefix = element . getNamespacePrefix ( i ) ; String uri = element . getNamespaceURI ( prefix ) ; if ( StringUtils . isBlank ( uri ) ) { continue ; } namespaces ++ ; } return namespaces > <NUM_LIT:0> ; } private boolean isArray ( Element element , boolean isTopLevel ) { boolean isArray = false ; String clazz = getClass ( element ) ; if ( clazz != null && clazz . equals ( JSONTypes . ARRAY ) ) { isArray = true ; } else if ( element . getAttributeCount ( ) == <NUM_LIT:0> ) { isArray = checkChildElements ( element , isTopLevel ) ; } else if ( element . getAttributeCount ( ) == <NUM_LIT:1> && ( element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) != null || element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) != null ) ) { isArray = checkChildElements ( element , isTopLevel ) ; } else if ( element . getAttributeCount ( ) == <NUM_LIT:2> && ( element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) != null && element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) != null ) ) { isArray = checkChildElements ( element , isTopLevel ) ; } if ( isArray ) { for ( int j = <NUM_LIT:0> ; j < element . getNamespaceDeclarationCount ( ) ; j ++ ) { String prefix = element . getNamespacePrefix ( j ) ; String uri = element . getNamespaceURI ( prefix ) ; if ( ! StringUtils . isBlank ( uri ) ) { return false ; } } } return isArray ; } private boolean isFunction ( Element element ) { int attrCount = element . getAttributeCount ( ) ; if ( attrCount > <NUM_LIT:0> ) { Attribute typeAttr = element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) ; Attribute paramsAttr = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; if ( attrCount == <NUM_LIT:1> && paramsAttr != null ) { return true ; } if ( attrCount == <NUM_LIT:2> && paramsAttr != null && typeAttr != null && ( typeAttr . getValue ( ) . compareToIgnoreCase ( JSONTypes . STRING ) == <NUM_LIT:0> || typeAttr . getValue ( ) . compareToIgnoreCase ( JSONTypes . FUNCTION ) == <NUM_LIT:0> ) ) { return true ; } } return false ; } private boolean isNullObject ( Element element ) { if ( element . getChildCount ( ) == <NUM_LIT:0> ) { if ( element . getAttributeCount ( ) == <NUM_LIT:0> ) { return true ; } else if ( element . getAttribute ( addJsonPrefix ( "<STR_LIT:null>" ) ) != null ) { return true ; } else if ( element . getAttributeCount ( ) == <NUM_LIT:1> && ( element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) != null || element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) != null ) ) { return true ; } else if ( element . getAttributeCount ( ) == <NUM_LIT:2> && ( element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) != null && element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) != null ) ) { return true ; } } if ( skipWhitespace && element . getChildCount ( ) == <NUM_LIT:1> && element . getChild ( <NUM_LIT:0> ) instanceof Text ) { return true ; } return false ; } private boolean isObject ( Element element , boolean isTopLevel ) { boolean isObject = false ; if ( ! isArray ( element , isTopLevel ) && ! isFunction ( element ) ) { if ( hasNamespaces ( element ) ) { return true ; } int attributeCount = element . getAttributeCount ( ) ; if ( attributeCount > <NUM_LIT:0> ) { int attrs = element . getAttribute ( addJsonPrefix ( "<STR_LIT:null>" ) ) == null ? <NUM_LIT:0> : <NUM_LIT:1> ; attrs += element . getAttribute ( addJsonPrefix ( "<STR_LIT:class>" ) ) == null ? <NUM_LIT:0> : <NUM_LIT:1> ; attrs += element . getAttribute ( addJsonPrefix ( "<STR_LIT:type>" ) ) == null ? <NUM_LIT:0> : <NUM_LIT:1> ; switch ( attributeCount ) { case <NUM_LIT:1> : if ( attrs == <NUM_LIT:0> ) { return true ; } break ; case <NUM_LIT:2> : if ( attrs < <NUM_LIT:2> ) { return true ; } break ; case <NUM_LIT:3> : if ( attrs < <NUM_LIT:3> ) { return true ; } break ; default : return true ; } } int childCount = element . getChildCount ( ) ; if ( childCount == <NUM_LIT:1> && element . getChild ( <NUM_LIT:0> ) instanceof Text ) { return isTopLevel ; } isObject = true ; } return isObject ; } private Element newElement ( String name ) { if ( name . indexOf ( '<CHAR_LIT::>' ) != - <NUM_LIT:1> ) { namespaceLenient = true ; } return namespaceLenient ? new CustomElement ( name ) : new Element ( name ) ; } private JSON processArrayElement ( Element element , String defaultType ) { JSONArray jsonArray = new JSONArray ( ) ; int childCount = element . getChildCount ( ) ; for ( int i = <NUM_LIT:0> ; i < childCount ; i ++ ) { Node child = element . getChild ( i ) ; if ( child instanceof Text ) { Text text = ( Text ) child ; if ( StringUtils . isNotBlank ( StringUtils . strip ( text . getValue ( ) ) ) ) { jsonArray . element ( text . getValue ( ) ) ; } } else if ( child instanceof Element ) { setValue ( jsonArray , ( Element ) child , defaultType ) ; } } return jsonArray ; } private Object processElement ( Element element , String type ) { if ( isNullObject ( element ) ) { return JSONNull . getInstance ( ) ; } else if ( isArray ( element , false ) ) { return processArrayElement ( element , type ) ; } else if ( isObject ( element , false ) ) { return processObjectElement ( element , type ) ; } else { return trimSpaceFromValue ( element . getValue ( ) ) ; } } private Element processJSONArray ( JSONArray array , Element root , String [ ] expandableProperties ) { int l = array . size ( ) ; for ( int i = <NUM_LIT:0> ; i < l ; i ++ ) { Object value = array . get ( i ) ; Element element = processJSONValue ( value , root , null , expandableProperties ) ; root . appendChild ( element ) ; } return root ; } private Element processJSONObject ( JSONObject jsonObject , Element root , String [ ] expandableProperties , boolean isRoot ) { if ( jsonObject . isNullObject ( ) ) { root . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:null>" ) , "<STR_LIT:true>" ) ) ; return root ; } else if ( jsonObject . isEmpty ( ) ) { return root ; } if ( isRoot ) { if ( ! rootNamespace . isEmpty ( ) ) { setNamespaceLenient ( true ) ; for ( Iterator entries = rootNamespace . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String prefix = ( String ) entry . getKey ( ) ; String uri = ( String ) entry . getValue ( ) ; if ( StringUtils . isBlank ( prefix ) ) { root . setNamespaceURI ( uri ) ; } else { root . addNamespaceDeclaration ( prefix , uri ) ; } } } } addNameSpaceToElement ( root ) ; Object [ ] names = jsonObject . names ( ) . toArray ( ) ; Arrays . sort ( names ) ; Element element = null ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { String name = ( String ) names [ i ] ; Object value = jsonObject . get ( name ) ; if ( name . startsWith ( "<STR_LIT>" ) ) { setNamespaceLenient ( true ) ; int colon = name . indexOf ( '<CHAR_LIT::>' ) ; if ( colon == - <NUM_LIT:1> ) { if ( StringUtils . isBlank ( root . getNamespaceURI ( ) ) ) { root . setNamespaceURI ( String . valueOf ( value ) ) ; } } else { String prefix = name . substring ( colon + <NUM_LIT:1> ) ; if ( StringUtils . isBlank ( root . getNamespaceURI ( prefix ) ) ) { root . addNamespaceDeclaration ( prefix , String . valueOf ( value ) ) ; } } } else if ( name . startsWith ( "<STR_LIT:@>" ) ) { root . addAttribute ( new Attribute ( name . substring ( <NUM_LIT:1> ) , String . valueOf ( value ) ) ) ; } else if ( name . equals ( "<STR_LIT>" ) ) { if ( value instanceof JSONArray ) { root . appendChild ( ( ( JSONArray ) value ) . join ( "<STR_LIT>" , true ) ) ; } else { root . appendChild ( String . valueOf ( value ) ) ; } } else if ( value instanceof JSONArray && ( ( ( JSONArray ) value ) . isExpandElements ( ) || ArrayUtils . contains ( expandableProperties , name ) ) ) { JSONArray array = ( JSONArray ) value ; int l = array . size ( ) ; for ( int j = <NUM_LIT:0> ; j < l ; j ++ ) { Object item = array . get ( j ) ; element = newElement ( name ) ; if ( item instanceof JSONObject ) { element = processJSONValue ( ( JSONObject ) item , root , element , expandableProperties ) ; } else if ( item instanceof JSONArray ) { element = processJSONValue ( ( JSONArray ) item , root , element , expandableProperties ) ; } else { element = processJSONValue ( item , root , element , expandableProperties ) ; } addNameSpaceToElement ( element ) ; root . appendChild ( element ) ; } } else { element = newElement ( name ) ; element = processJSONValue ( value , root , element , expandableProperties ) ; addNameSpaceToElement ( element ) ; root . appendChild ( element ) ; } } return root ; } private Element processJSONValue ( Object value , Element root , Element target , String [ ] expandableProperties ) { if ( target == null ) { target = newElement ( getElementName ( ) ) ; } if ( JSONUtils . isBoolean ( value ) ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:type>" ) , JSONTypes . BOOLEAN ) ) ; } target . appendChild ( value . toString ( ) ) ; } else if ( JSONUtils . isNumber ( value ) ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:type>" ) , JSONTypes . NUMBER ) ) ; } target . appendChild ( value . toString ( ) ) ; } else if ( JSONUtils . isFunction ( value ) ) { if ( value instanceof String ) { value = JSONFunction . parse ( ( String ) value ) ; } JSONFunction func = ( JSONFunction ) value ; if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:type>" ) , JSONTypes . FUNCTION ) ) ; } String params = ArrayUtils . toString ( func . getParams ( ) ) ; params = params . substring ( <NUM_LIT:1> ) ; params = params . substring ( <NUM_LIT:0> , params . length ( ) - <NUM_LIT:1> ) ; target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT>" ) , params ) ) ; target . appendChild ( new Text ( "<STR_LIT>" + func . getText ( ) + "<STR_LIT>" ) ) ; } else if ( JSONUtils . isString ( value ) ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:type>" ) , JSONTypes . STRING ) ) ; } target . appendChild ( value . toString ( ) ) ; } else if ( value instanceof JSONArray ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:class>" ) , JSONTypes . ARRAY ) ) ; } target = processJSONArray ( ( JSONArray ) value , target , expandableProperties ) ; } else if ( value instanceof JSONObject ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:class>" ) , JSONTypes . OBJECT ) ) ; } target = processJSONObject ( ( JSONObject ) value , target , expandableProperties , false ) ; } else if ( JSONUtils . isNull ( value ) ) { if ( isTypeHintsEnabled ( ) ) { target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:class>" ) , JSONTypes . OBJECT ) ) ; } target . addAttribute ( new Attribute ( addJsonPrefix ( "<STR_LIT:null>" ) , "<STR_LIT:true>" ) ) ; } return target ; } private JSON processObjectElement ( Element element , String defaultType ) { if ( isNullObject ( element ) ) { return JSONNull . getInstance ( ) ; } JSONObject jsonObject = new JSONObject ( ) ; if ( ! skipNamespaces ) { for ( int j = <NUM_LIT:0> ; j < element . getNamespaceDeclarationCount ( ) ; j ++ ) { String prefix = element . getNamespacePrefix ( j ) ; String uri = element . getNamespaceURI ( prefix ) ; if ( StringUtils . isBlank ( uri ) ) { continue ; } if ( ! StringUtils . isBlank ( prefix ) ) { prefix = "<STR_LIT::>" + prefix ; } setOrAccumulate ( jsonObject , "<STR_LIT>" + prefix , trimSpaceFromValue ( uri ) ) ; } } int attrCount = element . getAttributeCount ( ) ; for ( int i = <NUM_LIT:0> ; i < attrCount ; i ++ ) { Attribute attr = element . getAttribute ( i ) ; String attrname = attr . getQualifiedName ( ) ; if ( isTypeHintsEnabled ( ) && ( addJsonPrefix ( "<STR_LIT:class>" ) . compareToIgnoreCase ( attrname ) == <NUM_LIT:0> || addJsonPrefix ( "<STR_LIT:type>" ) . compareToIgnoreCase ( attrname ) == <NUM_LIT:0> ) ) { continue ; } String attrvalue = attr . getValue ( ) ; setOrAccumulate ( jsonObject , "<STR_LIT:@>" + removeNamespacePrefix ( attrname ) , trimSpaceFromValue ( attrvalue ) ) ; } int childCount = element . getChildCount ( ) ; for ( int i = <NUM_LIT:0> ; i < childCount ; i ++ ) { Node child = element . getChild ( i ) ; if ( child instanceof Text ) { Text text = ( Text ) child ; if ( StringUtils . isNotBlank ( StringUtils . strip ( text . getValue ( ) ) ) ) { setOrAccumulate ( jsonObject , "<STR_LIT>" , trimSpaceFromValue ( text . getValue ( ) ) ) ; } } else if ( child instanceof Element ) { setValue ( jsonObject , ( Element ) child , defaultType ) ; } } return jsonObject ; } private String removeNamespacePrefix ( String name ) { if ( isRemoveNamespacePrefixFromElements ( ) ) { int colon = name . indexOf ( '<CHAR_LIT::>' ) ; return colon != - <NUM_LIT:1> ? name . substring ( colon + <NUM_LIT:1> ) : name ; } return name ; } private void setOrAccumulate ( JSONObject jsonObject , String key , Object value ) { if ( jsonObject . has ( key ) ) { jsonObject . accumulate ( key , value ) ; Object val = jsonObject . get ( key ) ; if ( val instanceof JSONArray ) { ( ( JSONArray ) val ) . setExpandElements ( true ) ; } } else { jsonObject . element ( key , value ) ; } } private void setValue ( JSONArray jsonArray , Element element , String defaultType ) { String clazz = getClass ( element ) ; String type = getType ( element ) ; type = ( type == null ) ? defaultType : type ; if ( hasNamespaces ( element ) && ! skipNamespaces ) { jsonArray . element ( simplifyValue ( null , processElement ( element , type ) ) ) ; return ; } else if ( element . getAttributeCount ( ) > <NUM_LIT:0> ) { if ( isFunction ( element ) ) { Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; String [ ] params = null ; String text = element . getValue ( ) ; params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; jsonArray . element ( new JSONFunction ( params , text ) ) ; return ; } else { jsonArray . element ( simplifyValue ( null , processElement ( element , type ) ) ) ; return ; } } boolean classProcessed = false ; if ( clazz != null ) { if ( clazz . compareToIgnoreCase ( JSONTypes . ARRAY ) == <NUM_LIT:0> ) { jsonArray . element ( processArrayElement ( element , type ) ) ; classProcessed = true ; } else if ( clazz . compareToIgnoreCase ( JSONTypes . OBJECT ) == <NUM_LIT:0> ) { jsonArray . element ( simplifyValue ( null , processObjectElement ( element , type ) ) ) ; classProcessed = true ; } } if ( ! classProcessed ) { if ( type . compareToIgnoreCase ( JSONTypes . BOOLEAN ) == <NUM_LIT:0> ) { jsonArray . element ( Boolean . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . NUMBER ) == <NUM_LIT:0> ) { try { jsonArray . element ( Integer . valueOf ( element . getValue ( ) ) ) ; } catch ( NumberFormatException e ) { jsonArray . element ( Double . valueOf ( element . getValue ( ) ) ) ; } } else if ( type . compareToIgnoreCase ( JSONTypes . INTEGER ) == <NUM_LIT:0> ) { jsonArray . element ( Integer . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . FLOAT ) == <NUM_LIT:0> ) { jsonArray . element ( Double . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . FUNCTION ) == <NUM_LIT:0> ) { String [ ] params = null ; String text = element . getValue ( ) ; Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; if ( paramsAttribute != null ) { params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; } jsonArray . element ( new JSONFunction ( params , text ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . STRING ) == <NUM_LIT:0> ) { Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; if ( paramsAttribute != null ) { String [ ] params = null ; String text = element . getValue ( ) ; params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; jsonArray . element ( new JSONFunction ( params , text ) ) ; } else { if ( isArray ( element , false ) ) { jsonArray . element ( processArrayElement ( element , defaultType ) ) ; } else if ( isObject ( element , false ) ) { jsonArray . element ( simplifyValue ( null , processObjectElement ( element , defaultType ) ) ) ; } else { jsonArray . element ( trimSpaceFromValue ( element . getValue ( ) ) ) ; } } } } } private void setValue ( JSONObject jsonObject , Element element , String defaultType ) { String clazz = getClass ( element ) ; String type = getType ( element ) ; type = ( type == null ) ? defaultType : type ; String key = removeNamespacePrefix ( element . getQualifiedName ( ) ) ; if ( hasNamespaces ( element ) && ! skipNamespaces ) { setOrAccumulate ( jsonObject , key , simplifyValue ( jsonObject , processElement ( element , type ) ) ) ; return ; } else if ( element . getAttributeCount ( ) > <NUM_LIT:0> ) { if ( isFunction ( element ) ) { Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; String text = element . getValue ( ) ; String [ ] params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; setOrAccumulate ( jsonObject , key , new JSONFunction ( params , text ) ) ; return ; } } boolean classProcessed = false ; if ( clazz != null ) { if ( clazz . compareToIgnoreCase ( JSONTypes . ARRAY ) == <NUM_LIT:0> ) { setOrAccumulate ( jsonObject , key , processArrayElement ( element , type ) ) ; classProcessed = true ; } else if ( clazz . compareToIgnoreCase ( JSONTypes . OBJECT ) == <NUM_LIT:0> ) { setOrAccumulate ( jsonObject , key , simplifyValue ( jsonObject , processObjectElement ( element , type ) ) ) ; classProcessed = true ; } } if ( ! classProcessed ) { if ( type . compareToIgnoreCase ( JSONTypes . BOOLEAN ) == <NUM_LIT:0> ) { setOrAccumulate ( jsonObject , key , Boolean . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . NUMBER ) == <NUM_LIT:0> ) { try { setOrAccumulate ( jsonObject , key , Integer . valueOf ( element . getValue ( ) ) ) ; } catch ( NumberFormatException e ) { setOrAccumulate ( jsonObject , key , Double . valueOf ( element . getValue ( ) ) ) ; } } else if ( type . compareToIgnoreCase ( JSONTypes . INTEGER ) == <NUM_LIT:0> ) { setOrAccumulate ( jsonObject , key , Integer . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . FLOAT ) == <NUM_LIT:0> ) { setOrAccumulate ( jsonObject , key , Double . valueOf ( element . getValue ( ) ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . FUNCTION ) == <NUM_LIT:0> ) { String [ ] params = null ; String text = element . getValue ( ) ; Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; if ( paramsAttribute != null ) { params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; } setOrAccumulate ( jsonObject , key , new JSONFunction ( params , text ) ) ; } else if ( type . compareToIgnoreCase ( JSONTypes . STRING ) == <NUM_LIT:0> ) { Attribute paramsAttribute = element . getAttribute ( addJsonPrefix ( "<STR_LIT>" ) ) ; if ( paramsAttribute != null ) { String [ ] params = null ; String text = element . getValue ( ) ; params = StringUtils . split ( paramsAttribute . getValue ( ) , "<STR_LIT:U+002C>" ) ; setOrAccumulate ( jsonObject , key , new JSONFunction ( params , text ) ) ; } else { if ( isArray ( element , false ) ) { setOrAccumulate ( jsonObject , key , processArrayElement ( element , defaultType ) ) ; } else if ( isObject ( element , false ) ) { setOrAccumulate ( jsonObject , key , simplifyValue ( jsonObject , processObjectElement ( element , defaultType ) ) ) ; } else { setOrAccumulate ( jsonObject , key , trimSpaceFromValue ( element . getValue ( ) ) ) ; } } } } } private Object simplifyValue ( JSONObject parent , Object json ) { if ( json instanceof JSONObject ) { JSONObject object = ( JSONObject ) json ; if ( parent != null ) { for ( Iterator entries = parent . entrySet ( ) . iterator ( ) ; entries . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; if ( key . startsWith ( "<STR_LIT>" ) && value . equals ( object . opt ( key ) ) ) { object . remove ( key ) ; } } } if ( object . size ( ) == <NUM_LIT:1> && object . has ( "<STR_LIT>" ) ) { return object . get ( "<STR_LIT>" ) ; } } return json ; } private String trimSpaceFromValue ( String value ) { if ( isTrimSpaces ( ) ) { return value . trim ( ) ; } return value ; } private String writeDocument ( Document doc , String encoding ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { XomSerializer serializer = ( encoding == null ) ? new XomSerializer ( baos ) : new XomSerializer ( baos , encoding ) ; serializer . write ( doc ) ; encoding = serializer . getEncoding ( ) ; } catch ( IOException ioe ) { throw new JSONException ( ioe ) ; } String str = null ; try { str = baos . toString ( encoding ) ; } catch ( UnsupportedEncodingException uee ) { throw new JSONException ( uee ) ; } return str ; } private static class CustomElement extends Element { private static String getName ( String name ) { int colon = name . indexOf ( '<CHAR_LIT::>' ) ; if ( colon != - <NUM_LIT:1> ) { return name . substring ( colon + <NUM_LIT:1> ) ; } return name ; } private static String getPrefix ( String name ) { int colon = name . indexOf ( '<CHAR_LIT::>' ) ; if ( colon != - <NUM_LIT:1> ) { return name . substring ( <NUM_LIT:0> , colon ) ; } return "<STR_LIT>" ; } private String prefix ; public CustomElement ( String name ) { super ( CustomElement . getName ( name ) ) ; prefix = CustomElement . getPrefix ( name ) ; } public final String getQName ( ) { if ( prefix . length ( ) == <NUM_LIT:0> ) { return getLocalName ( ) ; } else { return prefix + "<STR_LIT::>" + getLocalName ( ) ; } } } private class XomSerializer extends Serializer { public XomSerializer ( OutputStream out ) { super ( out ) ; } public XomSerializer ( OutputStream out , String encoding ) throws UnsupportedEncodingException { super ( out , encoding ) ; } protected void write ( Text text ) throws IOException { String value = text . getValue ( ) ; if ( value . startsWith ( "<STR_LIT>" ) && value . endsWith ( "<STR_LIT>" ) ) { value = value . substring ( <NUM_LIT:9> ) ; value = value . substring ( <NUM_LIT:0> , value . length ( ) - <NUM_LIT:3> ) ; writeRaw ( "<STR_LIT>" ) ; writeRaw ( value ) ; writeRaw ( "<STR_LIT>" ) ; } else { super . write ( text ) ; } } protected void writeEmptyElementTag ( Element element ) throws IOException { if ( element instanceof CustomElement && isNamespaceLenient ( ) ) { writeTagBeginning ( ( CustomElement ) element ) ; writeRaw ( "<STR_LIT>" ) ; } else { super . writeEmptyElementTag ( element ) ; } } protected void writeEndTag ( Element element ) throws IOException { if ( element instanceof CustomElement && isNamespaceLenient ( ) ) { writeRaw ( "<STR_LIT>" ) ; writeRaw ( ( ( CustomElement ) element ) . getQName ( ) ) ; writeRaw ( "<STR_LIT:>>" ) ; } else { super . writeEndTag ( element ) ; } } protected void writeNamespaceDeclaration ( String prefix , String uri ) throws IOException { if ( ! StringUtils . isBlank ( uri ) ) { super . writeNamespaceDeclaration ( prefix , uri ) ; } } protected void writeStartTag ( Element element ) throws IOException { if ( element instanceof CustomElement && isNamespaceLenient ( ) ) { writeTagBeginning ( ( CustomElement ) element ) ; writeRaw ( "<STR_LIT:>>" ) ; } else { super . writeStartTag ( element ) ; } } private void writeTagBeginning ( CustomElement element ) throws IOException { writeRaw ( "<STR_LIT:<>" ) ; writeRaw ( element . getQName ( ) ) ; writeAttributes ( element ) ; writeNamespaceDeclarations ( element ) ; } } } </s>
<s> package net . sf . json ; import net . sf . json . util . JSONTokener ; import net . sf . json . util . JSONUtils ; public class JSONSerializer { public static Object toJava ( JSON json ) { return toJava ( json , new JsonConfig ( ) ) ; } public static Object toJava ( JSON json , JsonConfig jsonConfig ) { if ( JSONUtils . isNull ( json ) ) { return null ; } Object object = null ; if ( json instanceof JSONArray ) { if ( jsonConfig . getArrayMode ( ) == JsonConfig . MODE_OBJECT_ARRAY ) { object = JSONArray . toArray ( ( JSONArray ) json , jsonConfig ) ; } else { object = JSONArray . toCollection ( ( JSONArray ) json , jsonConfig ) ; } } else { object = JSONObject . toBean ( ( JSONObject ) json , jsonConfig ) ; } return object ; } public static JSON toJSON ( Object object ) { return toJSON ( object , new JsonConfig ( ) ) ; } public static JSON toJSON ( Object object , JsonConfig jsonConfig ) { JSON json = null ; if ( object == null ) { json = JSONNull . getInstance ( ) ; } else if ( object instanceof JSONString ) { json = toJSON ( ( JSONString ) object , jsonConfig ) ; } else if ( object instanceof String ) { json = toJSON ( ( String ) object , jsonConfig ) ; } else if ( JSONUtils . isArray ( object ) ) { json = JSONArray . fromObject ( object , jsonConfig ) ; } else { try { json = JSONObject . fromObject ( object , jsonConfig ) ; } catch ( JSONException e ) { if ( object instanceof JSONTokener ) { ( ( JSONTokener ) object ) . reset ( ) ; } json = JSONArray . fromObject ( object , jsonConfig ) ; } } return json ; } private static JSON toJSON ( JSONString string , JsonConfig jsonConfig ) { return toJSON ( string . toJSONString ( ) , jsonConfig ) ; } private static JSON toJSON ( String string , JsonConfig jsonConfig ) { JSON json = null ; if ( string . startsWith ( "<STR_LIT:[>" ) ) { json = JSONArray . fromObject ( string , jsonConfig ) ; } else if ( string . startsWith ( "<STR_LIT:{>" ) ) { json = JSONObject . fromObject ( string , jsonConfig ) ; } else if ( "<STR_LIT:null>" . equals ( string ) ) { json = JSONNull . getInstance ( ) ; } else { throw new JSONException ( "<STR_LIT>" ) ; } return json ; } } </s>
<s> package net . sf . json ; import java . io . IOException ; import java . io . Writer ; import java . io . Serializable ; public interface JSON extends Serializable { boolean isArray ( ) ; boolean isEmpty ( ) ; int size ( ) ; String toString ( int indentFactor ) ; String toString ( int indentFactor , int indent ) ; Writer write ( Writer writer ) throws IOException ; Writer writeCanonical ( Writer w ) throws IOException ; } </s>
<s> package net . sf . json ; import org . apache . commons . lang . exception . NestableRuntimeException ; public class JSONException extends NestableRuntimeException { private static final long serialVersionUID = <NUM_LIT> ; public JSONException ( ) { super ( ) ; } public JSONException ( String msg ) { super ( msg , null ) ; } public JSONException ( String msg , Throwable cause ) { super ( msg , cause ) ; } public JSONException ( Throwable cause ) { super ( ( cause == null ? null : cause . toString ( ) ) , cause ) ; } } </s>
<s> package net . sf . json . processors ; import java . util . Calendar ; import java . util . Date ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; public class JsDateJsonBeanProcessor implements JsonBeanProcessor { public JSONObject processBean ( Object bean , JsonConfig jsonConfig ) { JSONObject jsonObject = null ; if ( bean instanceof java . sql . Date ) { bean = new Date ( ( ( java . sql . Date ) bean ) . getTime ( ) ) ; } if ( bean instanceof Date ) { Calendar c = Calendar . getInstance ( ) ; c . setTime ( ( Date ) bean ) ; jsonObject = new JSONObject ( ) . element ( "<STR_LIT>" , c . get ( Calendar . YEAR ) ) . element ( "<STR_LIT>" , c . get ( Calendar . MONTH ) ) . element ( "<STR_LIT>" , c . get ( Calendar . DAY_OF_MONTH ) ) . element ( "<STR_LIT>" , c . get ( Calendar . HOUR_OF_DAY ) ) . element ( "<STR_LIT>" , c . get ( Calendar . MINUTE ) ) . element ( "<STR_LIT>" , c . get ( Calendar . SECOND ) ) . element ( "<STR_LIT>" , c . get ( Calendar . MILLISECOND ) ) ; } else { jsonObject = new JSONObject ( true ) ; } return jsonObject ; } } </s>
<s> package net . sf . json . processors ; import java . math . BigDecimal ; import java . math . BigInteger ; import net . sf . json . JSON ; import net . sf . json . JSONFunction ; import net . sf . json . JSONNull ; import net . sf . json . JSONString ; public final class JsonVerifier { public static boolean isValidJsonValue ( Object value ) { if ( JSONNull . getInstance ( ) . equals ( value ) || value instanceof JSON || value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long || value instanceof Double || value instanceof BigInteger || value instanceof BigDecimal || value instanceof JSONFunction || value instanceof JSONString || value instanceof String ) { return true ; } return false ; } } </s>