summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-09-11 13:52:12 +0200
committerSimon Rettberg2019-09-11 13:52:12 +0200
commit274c2eb328dce495ac2ab8f6bf314604ded7b6b9 (patch)
tree9629092d0abdf0347112397186d0a210049c5f98
parent[vm] Move workaround to actually take effect (diff)
downloadmaster-sync-shared-master.tar.gz
master-sync-shared-master.tar.xz
master-sync-shared-master.zip
Json: Fix deserialization of bools in Thrift classesHEADmaster
-rw-r--r--src/main/java/org/openslx/util/Json.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/util/Json.java b/src/main/java/org/openslx/util/Json.java
index d9fb659..f92bb58 100644
--- a/src/main/java/org/openslx/util/Json.java
+++ b/src/main/java/org/openslx/util/Json.java
@@ -47,12 +47,18 @@ public class Json {
String upperName = field.getName().substring(0, 1).toUpperCase()
+ field.getName().substring(1);
try {
+ Method getter;
+ try {
+ getter = thriftClass.getMethod( "get" + upperName );
+ } catch (NoSuchMethodException e) {
+ getter = thriftClass.getMethod( "is" + upperName );
+ }
fields.add( new ThriftField( field,
- thriftClass.getMethod( "get" + upperName ),
+ getter,
thriftClass.getMethod( "set" + upperName, field.getType() ),
thriftClass.getMethod( "isSet" + upperName) ) );
} catch (NoSuchMethodException e) {
- // Not a thrift field, apparently
+ LOGGER.warn( "Nein", e );
}
}
synchronized ( Json.class ) {
@@ -115,7 +121,9 @@ public class Json {
throws JsonParseException {
if (!(json instanceof JsonObject))
throw new JsonParseException("Need a json object, have " + json.getClass().getSimpleName());
+ // We're deserializing a json object {..} here
JsonObject obj = (JsonObject) json;
+ // Create the Thrift object we want to deserialize into
final T inst;
try {
inst = clazz.newInstance();
@@ -123,6 +131,7 @@ public class Json {
LOGGER.warn("Could not deserialize to class " + clazz.getName(), e);
throw new JsonParseException("Cannot instantiate class " + clazz.getSimpleName());
}
+ // Iterate over all fields in the Thrift object
for (ThriftField field : fields) {
JsonElement element = obj.get(field.field.getName());
if (element == null || element.isJsonNull())
@@ -142,7 +151,8 @@ public class Json {
JsonObject o = new JsonObject();
for ( ThriftField thrift : fields ) {
try {
- if ( !(Boolean)thrift.isset.invoke( thriftClass ) )
+ Object ret = thrift.isset.invoke( thriftClass );
+ if ( !(ret instanceof Boolean) || !(Boolean)ret )
continue;
Object value = thrift.getter.invoke( thriftClass );
if ( value == null )