mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for Issue 11 - Jaxrs and Inheritance - BeanDescriptor bug
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user