Fix for Issue 11 - Jaxrs and Inheritance - BeanDescriptor bug

This commit is contained in:
Robin Bygrave
2013-04-25 16:10:34 +12:00
parent 85f3a8987d
commit 97cc2984cf
7 changed files with 188 additions and 13 deletions
@@ -2337,24 +2337,31 @@ public class BeanDescriptor<T> {
return jsonReadObject(ctx, path);
} else {
// read the discriminator value to determine the correct sub type
// check for the discriminator value to determine the correct sub type
String discColumn = inheritInfo.getRoot().getDiscriminatorColumn();
if (!ctx.readKeyNext()) {
String msg = "Error reading inheritance discriminator - expected [" + discColumn + "] but no json key?";
throw new TextException(msg);
}
String propName = ctx.getTokenKey();
if (!propName.equalsIgnoreCase(discColumn)) {
String msg = "Error reading inheritance discriminator - expected [" + discColumn + "] but read [" + propName + "]";
throw new TextException(msg);
}
String discValue = ctx.readScalarValue();
if (!ctx.readValueNext()) {
String msg = "Error reading inheritance discriminator [" + discColumn + "]. Expected more json name values?";
throw new TextException(msg);
String propName = ctx.getTokenKey();
String discValue;
if (propName.equalsIgnoreCase(discColumn)) {
discValue = ctx.readScalarValue();
if (!ctx.readValueNext()) {
// Expected to read a comma to setup for reading the real properties of the bean
String msg = "Error reading inheritance discriminator [" + discColumn + "]. Expected more json name values?";
throw new TextException(msg);
}
} else {
// Assume that the we are just reading using this bean type
// Push the token key back so that it is re-read as it is one
// of the real properties of the bean itself
ctx.pushTokenKey();
discValue = inheritInfo.getDiscriminatorStringValue();
}
// determine the sub type for this particular json object
@@ -8,10 +8,18 @@ public class ReadBasicJsonContext implements ReadJsonInterface {
private char tokenStart;
private String tokenKey;
private boolean pushedTokenKey;
public ReadBasicJsonContext(ReadJsonSource src) {
this.src = src;
}
/**
* Push the current token key back onto the 'stack'.
*/
public void pushTokenKey() {
pushedTokenKey = true;
}
public char getToken() {
return tokenStart;
@@ -84,7 +92,13 @@ public class ReadBasicJsonContext implements ReadJsonInterface {
}
public void readNextToken() {
if (pushedTokenKey) {
// Do nothing
pushedTokenKey = false;
return;
}
ignoreWhiteSpace();
tokenStart = src.nextChar("EOF finding next token");
@@ -179,4 +179,6 @@ public class ReadJsonContext extends ReadBasicJsonContext {
}
}