1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-18 00:10:51 -07:00

More trickery from the bean

This commit is contained in:
stleary 2015-05-07 23:04:26 -05:00
parent ad440b4f11
commit 49d4985828

View file

@ -1,13 +1,26 @@
package org.json.junit; package org.json.junit;
public class MyBean { import java.io.*;
public int intKey;
public double doubleKey;
public String stringKey;
public String complexStringKey;
public boolean trueKey;
public boolean falseKey;
// bean must be serializable
public class MyBean implements Serializable {
// bean properties should be private
private static final long serialVersionUID = 1L;
private int intKey;
private double doubleKey;
private String stringKey;
private String complexStringKey;
private boolean trueKey;
private boolean falseKey;
/**
* Throw in a few public properties in order to test building
* from an Object.
*/
public String publicStr;
public int publicInt;
// bean needs a default ctor
public MyBean() { public MyBean() {
intKey = 42; intKey = 42;
doubleKey = -23.45e7; doubleKey = -23.45e7;
@ -15,7 +28,12 @@ public class MyBean {
complexStringKey = "h\be\tllo w\u1234orld!"; complexStringKey = "h\be\tllo w\u1234orld!";
trueKey = true; trueKey = true;
falseKey = false; falseKey = false;
publicStr = "abc";
publicInt = 42;
} }
// need getters, but don't need setters
public int getIntKey() { public int getIntKey() {
return intKey; return intKey;
} }
@ -34,4 +52,29 @@ public class MyBean {
public boolean isFalseKey() { public boolean isFalseKey() {
return falseKey; return falseKey;
} }
/**
* Just a random invalid JSON getter, not even backed up by a property
*/
public StringReader getStringReaderKey() {
return (new StringReader("") {
/**
* TODO: Need to understand why returning a string
* turns this into an empty JSONObject,
* but not overriding turns this into a string.
*/
@Override
public String toString(){
return "Whatever";
}
});
}
// bean hashcode is recommended
public int hashCode() {
return super.hashCode();
}
// bean equals is recommended
public boolean equals(Object obj) {
return super.equals(obj);
}
} }