Skip to content

Commit 13caac7

Browse files
committed
fix: ST5AS-207 Project PUT
1 parent 023a6b5 commit 13caac7

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

app/jackson/JpaIdentityDeserializer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOExcepti
5252
if (p.currentToken() != JsonToken.START_OBJECT) {
5353
throw new JsonParseException(p, "Expected START_OBJECT. Received " + p.getCurrentName() + ".");
5454
}
55+
T t = null;
5556
JsonToken token;
5657
while ((token = p.nextToken()) != null && token != JsonToken.END_OBJECT) {
57-
if (token == JsonToken.FIELD_NAME && isIdentityField(p.getCurrentName())) {
58-
if (p.nextToken() == null) {
58+
if (t == null && token == JsonToken.FIELD_NAME && isIdentityField(p.getCurrentName())) {
59+
token = p.nextToken();
60+
if (token == null) {
5961
throw new JsonParseException(p, "No value for identity field.");
6062
}
61-
return deserializeFromIdentity(p);
63+
t = deserializeFromIdentity(p);
6264
}
6365
}
64-
return null;
66+
return t;
6567
}
6668

6769
@Override

app/jackson/RecordSerialization.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ protected boolean isIdentityField(String field) {
6666
}
6767

6868
@Override
69-
@SuppressWarnings("unchecked")
7069
protected R deserializeFromIdentity(JsonParser parser) throws IOException {
7170
UUID id = UUID.fromString(parser.getText());
72-
Record record = getEntityManager().find(getRecordClass(), id);
71+
R record = getEntityManager().find(getRecordClass(), id);
7372
if (record == null) {
7473
throw new IOException(new EntityNotFoundException("Record " + id + " not found."));
7574
}
76-
return (R) record;
75+
return record;
7776
}
7877
}
7978

0 commit comments

Comments
 (0)