299455 Enum support in JSONPojoConvertor
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1194 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
eaab420027
commit
3987ed20aa
|
@ -8,6 +8,7 @@ jetty-7.0.2-SNAPSHOT
|
|||
+ 298145 Reorganized test harness to separate the HTTP PUT and HTTP GET test URLs
|
||||
+ 298234 Unit test for jetty-client handling different HTTP error codes
|
||||
+ 298667 DeploymentManager uses ContextProvider and WebAppProvider
|
||||
+ 299455 Enum support in JSONPojoConvertor
|
||||
+ JETTY-910 Allow request listeners to access session
|
||||
+ JETTY-1153 System property for UrlEncoded charset
|
||||
+ JETTY-1155 HttpConnection.close notifies HttpExchange
|
||||
|
|
|
@ -286,8 +286,14 @@ public class JSONPojoConvertor implements JSON.Convertor
|
|||
protected void invokeObject(Object obj, Object value) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
if(_numberType!=null && value instanceof Number)
|
||||
if (_type.isEnum())
|
||||
{
|
||||
_method.invoke(obj, new Object[]{Enum.valueOf((Class<? extends Enum>)_type,value.toString())});
|
||||
}
|
||||
else if(_numberType!=null && value instanceof Number)
|
||||
{
|
||||
_method.invoke(obj, new Object[]{_numberType.getActualValue((Number)value)});
|
||||
}
|
||||
else if(_componentType!=null && value.getClass().isArray())
|
||||
{
|
||||
if(_numberType==null)
|
||||
|
|
|
@ -85,17 +85,15 @@ public class JSONPojoConvertorTest extends TestCase
|
|||
foo._double2 = new Double(10000.22222d);
|
||||
|
||||
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo));
|
||||
bar.setColor(Color.Blue);
|
||||
|
||||
String s = json.toJSON(bar);
|
||||
|
||||
Object obj = json.parse(new JSON.StringSource(s));
|
||||
|
||||
assertTrue(obj instanceof Bar);
|
||||
|
||||
Bar br = (Bar)obj;
|
||||
|
||||
Baz bz = br.getBaz();
|
||||
|
||||
Foo f = bz.getFoo();
|
||||
|
||||
assertNull(br.getTitle());
|
||||
|
@ -107,14 +105,18 @@ public class JSONPojoConvertorTest extends TestCase
|
|||
assertNull(f.getInt2());
|
||||
assertFalse(foo.getInt2().equals(f.getInt2()));
|
||||
assertNull(f.getName());
|
||||
assertEquals(Color.Blue,br.getColor());
|
||||
}
|
||||
|
||||
enum Color { Red, Green, Blue };
|
||||
|
||||
public static class Bar
|
||||
{
|
||||
private String _title, _nullTest;
|
||||
private Baz _baz;
|
||||
private boolean _boolean1;
|
||||
private Baz[] _bazs;
|
||||
private Color _color=Color.Red;
|
||||
|
||||
public Bar()
|
||||
{
|
||||
|
@ -137,11 +139,13 @@ public class JSONPojoConvertorTest extends TestCase
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuffer().append("\n=== ").append(getClass().getSimpleName()).append(" ===")
|
||||
return new StringBuffer()
|
||||
.append("\n=== ").append(getClass().getSimpleName()).append(" ===")
|
||||
.append("\ntitle: ").append(getTitle())
|
||||
.append("\nboolean1: ").append(isBoolean1())
|
||||
.append("\nnullTest: ").append(getNullTest())
|
||||
.append("\nbaz: ").append(getBaz()).toString();
|
||||
.append("\nbaz: ").append(getBaz())
|
||||
.append("\ncolor: ").append(_color).toString();
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
|
@ -194,6 +198,18 @@ public class JSONPojoConvertorTest extends TestCase
|
|||
{
|
||||
return _bazs;
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
public void setColor(Color color)
|
||||
{
|
||||
_color = color;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class Baz
|
||||
|
|
Loading…
Reference in New Issue