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
|
+ 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
|
+ 298234 Unit test for jetty-client handling different HTTP error codes
|
||||||
+ 298667 DeploymentManager uses ContextProvider and WebAppProvider
|
+ 298667 DeploymentManager uses ContextProvider and WebAppProvider
|
||||||
|
+ 299455 Enum support in JSONPojoConvertor
|
||||||
+ JETTY-910 Allow request listeners to access session
|
+ JETTY-910 Allow request listeners to access session
|
||||||
+ JETTY-1153 System property for UrlEncoded charset
|
+ JETTY-1153 System property for UrlEncoded charset
|
||||||
+ JETTY-1155 HttpConnection.close notifies HttpExchange
|
+ 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,
|
protected void invokeObject(Object obj, Object value) throws IllegalArgumentException,
|
||||||
IllegalAccessException, InvocationTargetException
|
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)});
|
_method.invoke(obj, new Object[]{_numberType.getActualValue((Number)value)});
|
||||||
|
}
|
||||||
else if(_componentType!=null && value.getClass().isArray())
|
else if(_componentType!=null && value.getClass().isArray())
|
||||||
{
|
{
|
||||||
if(_numberType==null)
|
if(_numberType==null)
|
||||||
|
|
|
@ -85,17 +85,15 @@ public class JSONPojoConvertorTest extends TestCase
|
||||||
foo._double2 = new Double(10000.22222d);
|
foo._double2 = new Double(10000.22222d);
|
||||||
|
|
||||||
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo));
|
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo));
|
||||||
|
bar.setColor(Color.Blue);
|
||||||
|
|
||||||
String s = json.toJSON(bar);
|
String s = json.toJSON(bar);
|
||||||
|
|
||||||
Object obj = json.parse(new JSON.StringSource(s));
|
Object obj = json.parse(new JSON.StringSource(s));
|
||||||
|
|
||||||
assertTrue(obj instanceof Bar);
|
assertTrue(obj instanceof Bar);
|
||||||
|
|
||||||
Bar br = (Bar)obj;
|
Bar br = (Bar)obj;
|
||||||
|
|
||||||
Baz bz = br.getBaz();
|
Baz bz = br.getBaz();
|
||||||
|
|
||||||
Foo f = bz.getFoo();
|
Foo f = bz.getFoo();
|
||||||
|
|
||||||
assertNull(br.getTitle());
|
assertNull(br.getTitle());
|
||||||
|
@ -107,14 +105,18 @@ public class JSONPojoConvertorTest extends TestCase
|
||||||
assertNull(f.getInt2());
|
assertNull(f.getInt2());
|
||||||
assertFalse(foo.getInt2().equals(f.getInt2()));
|
assertFalse(foo.getInt2().equals(f.getInt2()));
|
||||||
assertNull(f.getName());
|
assertNull(f.getName());
|
||||||
|
assertEquals(Color.Blue,br.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Color { Red, Green, Blue };
|
||||||
|
|
||||||
public static class Bar
|
public static class Bar
|
||||||
{
|
{
|
||||||
private String _title, _nullTest;
|
private String _title, _nullTest;
|
||||||
private Baz _baz;
|
private Baz _baz;
|
||||||
private boolean _boolean1;
|
private boolean _boolean1;
|
||||||
private Baz[] _bazs;
|
private Baz[] _bazs;
|
||||||
|
private Color _color=Color.Red;
|
||||||
|
|
||||||
public Bar()
|
public Bar()
|
||||||
{
|
{
|
||||||
|
@ -137,11 +139,13 @@ public class JSONPojoConvertorTest extends TestCase
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
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("\ntitle: ").append(getTitle())
|
||||||
.append("\nboolean1: ").append(isBoolean1())
|
.append("\nboolean1: ").append(isBoolean1())
|
||||||
.append("\nnullTest: ").append(getNullTest())
|
.append("\nnullTest: ").append(getNullTest())
|
||||||
.append("\nbaz: ").append(getBaz()).toString();
|
.append("\nbaz: ").append(getBaz())
|
||||||
|
.append("\ncolor: ").append(_color).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title)
|
public void setTitle(String title)
|
||||||
|
@ -194,6 +198,18 @@ public class JSONPojoConvertorTest extends TestCase
|
||||||
{
|
{
|
||||||
return _bazs;
|
return _bazs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getColor()
|
||||||
|
{
|
||||||
|
return _color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color)
|
||||||
|
{
|
||||||
|
_color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Baz
|
public static class Baz
|
||||||
|
|
Loading…
Reference in New Issue