mirror of
https://github.com/stleary/JSON-java.git
synced 2026-03-20 00:00:50 -04:00
new test cases to support bean annotation
This commit is contained in:
@@ -20,7 +20,7 @@ public class GenericBean<T extends Number & Comparable<T>> implements MyBean {
|
||||
}
|
||||
|
||||
/** */
|
||||
private T genericValue;
|
||||
protected T genericValue;
|
||||
/** to be used by the calling test to see how often the getter is called */
|
||||
public int genericGetCounter;
|
||||
/** to be used by the calling test to see how often the setter is called */
|
||||
|
||||
@@ -13,7 +13,7 @@ public class GenericBeanInt extends GenericBean<Integer> {
|
||||
|
||||
/** @return the a */
|
||||
public char getA() {
|
||||
return a;
|
||||
return this.a;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,6 +25,33 @@ public class GenericBeanInt extends GenericBean<Integer> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should not be beanable
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean get() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should not be beanable
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean is() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be beanable
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean isB() {
|
||||
return this.genericValue.equals((Integer.valueOf(this.a+1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param genericValue
|
||||
* the value to initiate with.
|
||||
|
||||
20
src/test/java/org/json/junit/data/MyBeanCustomName.java
Normal file
20
src/test/java/org/json/junit/data/MyBeanCustomName.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.json.junit.data;
|
||||
|
||||
import org.json.JSONPropertyName;
|
||||
|
||||
/**
|
||||
* Test bean for the {@link JSONPropertyName} annotation.
|
||||
*/
|
||||
public class MyBeanCustomName implements MyBeanCustomNameInterface {
|
||||
public int getSomeInt() { return 42; }
|
||||
@JSONPropertyName("")
|
||||
public long getSomeLong() { return 42L; }
|
||||
@JSONPropertyName("myStringField")
|
||||
public String getSomeString() { return "someStringValue"; }
|
||||
@JSONPropertyName("Some Weird NAme that Normally Wouldn't be possible!")
|
||||
public double getMyDouble() { return 0.0d; }
|
||||
@Override
|
||||
public float getSomeFloat() { return 2.0f; }
|
||||
@Override
|
||||
public int getIgnoredInt() { return 40; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.json.junit.data;
|
||||
|
||||
import org.json.JSONPropertyIgnore;
|
||||
import org.json.JSONPropertyName;
|
||||
|
||||
public interface MyBeanCustomNameInterface {
|
||||
@JSONPropertyName("InterfaceField")
|
||||
float getSomeFloat();
|
||||
@JSONPropertyIgnore
|
||||
int getIgnoredInt();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.json.junit.data;
|
||||
|
||||
import org.json.JSONPropertyIgnore;
|
||||
import org.json.JSONPropertyName;
|
||||
|
||||
/**
|
||||
* Test bean to verify that the {@link org.json.JSONPropertyName} annotation
|
||||
* is inherited.
|
||||
*/
|
||||
public class MyBeanCustomNameSubClass extends MyBeanCustomName {
|
||||
@Override
|
||||
@JSONPropertyName("forcedInt")
|
||||
public int getIgnoredInt() { return 42*42; }
|
||||
@Override
|
||||
@JSONPropertyName("newIntFieldName")
|
||||
public int getSomeInt() { return 43; }
|
||||
@Override
|
||||
public String getSomeString() { return "subClassString"; }
|
||||
@Override
|
||||
@JSONPropertyName("AMoreNormalName")
|
||||
public double getMyDouble() { return 1.0d; }
|
||||
@Override
|
||||
public float getSomeFloat() { return 3.0f; }
|
||||
@JSONPropertyIgnore
|
||||
@JSONPropertyName("ShouldBeIgnored")
|
||||
public boolean getShouldNotBeJSON() { return true; }
|
||||
@JSONPropertyName("Getable")
|
||||
public boolean getable() { return true; }
|
||||
}
|
||||
Reference in New Issue
Block a user