Skip to content

Commit ded612b

Browse files
committed
Last event method removed
Signed-off-by: David Kral <[email protected]>
1 parent 16badee commit ded612b

22 files changed

+87
-103
lines changed

src/main/java/org/eclipse/yasson/internal/DeserializationContextImpl.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -31,7 +31,6 @@
3131
*/
3232
public class DeserializationContextImpl extends ProcessingContext implements DeserializationContext {
3333
private final List<Runnable> delayedSetters = new ArrayList<>();
34-
private JsonParser.Event lastValueEvent;
3534
private Customization customization = ClassCustomization.empty();
3635
private Object instance;
3736

@@ -51,7 +50,6 @@ public DeserializationContextImpl(JsonbContext jsonbContext) {
5150
*/
5251
public DeserializationContextImpl(DeserializationContextImpl context) {
5352
super(context.getJsonbContext());
54-
this.lastValueEvent = context.lastValueEvent;
5553
}
5654

5755
/**
@@ -81,24 +79,6 @@ public List<Runnable> getDeferredDeserializers() {
8179
return delayedSetters;
8280
}
8381

84-
/**
85-
* Return last obtained {@link JsonParser.Event} event.
86-
*
87-
* @return last obtained event
88-
*/
89-
public JsonParser.Event getLastValueEvent() {
90-
return lastValueEvent;
91-
}
92-
93-
/**
94-
* Set last obtained {@link JsonParser.Event} event.
95-
*
96-
* @param lastValueEvent last obtained event
97-
*/
98-
public void setLastValueEvent(JsonParser.Event lastValueEvent) {
99-
this.lastValueEvent = lastValueEvent;
100-
}
101-
10282
/**
10383
* Return customization used by currently processed user defined deserializer.
10484
*
@@ -130,9 +110,10 @@ public <T> T deserialize(Type type, JsonParser parser) {
130110
@SuppressWarnings("unchecked")
131111
private <T> T deserializeItem(Type type, JsonParser parser) {
132112
try {
133-
if (lastValueEvent == null) {
134-
lastValueEvent = parser.next();
135-
checkState();
113+
JsonParser.Event startingEvent = parser.currentEvent();
114+
if (startingEvent == null || startingEvent == JsonParser.Event.KEY_NAME) {
115+
parser.next();
116+
checkState(parser);
136117
}
137118
ModelDeserializer<JsonParser> modelDeserializer = getJsonbContext().getChainModelCreator().deserializerChain(type);
138119
return (T) modelDeserializer.deserialize(parser, this);
@@ -143,8 +124,8 @@ private <T> T deserializeItem(Type type, JsonParser parser) {
143124
}
144125
}
145126

146-
private void checkState() {
147-
if (lastValueEvent == JsonParser.Event.KEY_NAME) {
127+
private void checkState(JsonParser parser) {
128+
if (parser.currentEvent() == JsonParser.Event.KEY_NAME) {
148129
throw new JsonbException("JsonParser has incorrect position as the first event: KEY_NAME");
149130
}
150131
}

src/main/java/org/eclipse/yasson/internal/deserializer/ArrayDeserializer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -35,9 +35,7 @@ class ArrayDeserializer implements ModelDeserializer<JsonParser> {
3535
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
3636
Collection<Object> collection = new ArrayList<>();
3737
while (parser.hasNext()) {
38-
final JsonParser.Event next = parser.next();
39-
context.setLastValueEvent(next);
40-
switch (next) {
38+
switch (parser.next()) {
4139
case START_OBJECT:
4240
case START_ARRAY:
4341
case VALUE_STRING:
@@ -51,7 +49,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
5149
case END_ARRAY:
5250
return collection;
5351
default:
54-
throw new JsonbException("Unexpected state: " + next);
52+
throw new JsonbException("Unexpected state: " + parser.currentEvent());
5553
}
5654
}
5755
return collection;

src/main/java/org/eclipse/yasson/internal/deserializer/CollectionDeserializer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -35,9 +35,7 @@ class CollectionDeserializer implements ModelDeserializer<JsonParser> {
3535
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
3636
Collection<Object> collection = (Collection<Object>) context.getInstance();
3737
while (parser.hasNext()) {
38-
final JsonParser.Event next = parser.next();
39-
context.setLastValueEvent(next);
40-
switch (next) {
38+
switch (parser.next()) {
4139
case VALUE_NULL:
4240
case START_OBJECT:
4341
case START_ARRAY:
@@ -51,7 +49,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
5149
case END_ARRAY:
5250
return collection;
5351
default:
54-
throw new JsonbException("Unexpected state: " + next);
52+
throw new JsonbException("Unexpected state: " + parser.currentEvent());
5553
}
5654
}
5755
return collection;

src/main/java/org/eclipse/yasson/internal/deserializer/ContextSwitcher.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -33,8 +33,6 @@ class ContextSwitcher implements ModelDeserializer<JsonParser> {
3333
@Override
3434
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
3535
DeserializationContextImpl ctx = new DeserializationContextImpl(context);
36-
Object returnedValue = delegate.deserialize(modelDeserializer.deserialize(value, ctx), context);
37-
context.setLastValueEvent(ctx.getLastValueEvent());
38-
return returnedValue;
36+
return delegate.deserialize(modelDeserializer.deserialize(value, ctx), context);
3937
}
4038
}

src/main/java/org/eclipse/yasson/internal/deserializer/InheritanceInstanceCreator.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -23,8 +23,6 @@
2323
import org.eclipse.yasson.internal.jsonstructure.JsonStructureToParserAdapter;
2424
import org.eclipse.yasson.internal.model.customization.TypeInheritanceConfiguration;
2525

26-
import static jakarta.json.stream.JsonParser.Event;
27-
2826
/**
2927
* Instance creator following the inheritance structure defined by {@link jakarta.json.bind.annotation.JsonbTypeInfo}.
3028
*/
@@ -58,8 +56,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
5856
.build();
5957
jsonParser = new JsonStructureToParserAdapter(newJsonObject);
6058
//To get to the first event
61-
Event event = jsonParser.next();
62-
context.setLastValueEvent(event);
59+
jsonParser.next();
6360
Class<?> polymorphicTypeClass;
6461
if (alias == null) {
6562
return defaultProcessor.deserialize(jsonParser, context);

src/main/java/org/eclipse/yasson/internal/deserializer/JsonbCreatorDeserializer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -68,9 +68,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
6868
String key = null;
6969
Map<String, Object> paramValues = new HashMap<>();
7070
while (parser.hasNext()) {
71-
final JsonParser.Event next = parser.next();
72-
context.setLastValueEvent(next);
73-
switch (next) {
71+
switch (parser.next()) {
7472
case KEY_NAME:
7573
key = renamer.apply(parser.getString());
7674
break;
@@ -94,7 +92,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
9492
throw new JsonbException(Messages.getMessage(MessageKeys.UNKNOWN_JSON_PROPERTY, key, clazz));
9593
} else {
9694
//We need to skip the corresponding structure if property key was not found
97-
VALUE_SKIPPERS.getOrDefault(next, NOOP).accept(parser);
95+
VALUE_SKIPPERS.getOrDefault(parser.currentEvent(), NOOP).accept(parser);
9896
}
9997
break;
10098
case END_OBJECT:
@@ -112,7 +110,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
112110
context.getDeferredDeserializers().clear();
113111
return context.getInstance();
114112
default:
115-
throw new JsonbException("Unexpected state: " + next);
113+
throw new JsonbException("Unexpected state: " + parser.currentEvent());
116114
}
117115
}
118116
return context.getInstance();

src/main/java/org/eclipse/yasson/internal/deserializer/MapDeserializer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -43,9 +43,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
4343
Mode mode = Mode.NONE;
4444
State state = State.NEXT;
4545
while (parser.hasNext()) {
46-
final JsonParser.Event next = parser.next();
47-
context.setLastValueEvent(next);
48-
switch (next) {
46+
switch (parser.next()) {
4947
case KEY_NAME:
5048
mode = mode == Mode.NONE ? Mode.NORMAL : mode;
5149
if (mode == Mode.NORMAL) {
@@ -89,7 +87,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
8987
case END_ARRAY:
9088
return map;
9189
default:
92-
throw new JsonbException("Unexpected state: " + next);
90+
throw new JsonbException("Unexpected state: " + parser.currentEvent());
9391
}
9492
}
9593
return map;

src/main/java/org/eclipse/yasson/internal/deserializer/NullCheckDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -42,7 +42,7 @@ public NullCheckDeserializer(ModelDeserializer<JsonParser> nonNullDeserializer,
4242

4343
@Override
4444
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
45-
if (context.getLastValueEvent() != JsonParser.Event.VALUE_NULL) {
45+
if (value.currentEvent() != JsonParser.Event.VALUE_NULL) {
4646
return nonNullDeserializer.deserialize(value, context);
4747
}
4848
return nullDeserializer.deserialize(null, context);

src/main/java/org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ class ObjectDeserializer implements ModelDeserializer<JsonParser> {
6060
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
6161
String key = null;
6262
while (parser.hasNext()) {
63-
final JsonParser.Event next = parser.next();
64-
context.setLastValueEvent(next);
65-
switch (next) {
63+
switch (parser.next()) {
6664
case KEY_NAME:
6765
key = renamer.apply(parser.getString());
6866
break;
@@ -83,15 +81,15 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
8381
throw new JsonbException(Messages.getMessage(MessageKeys.UNKNOWN_JSON_PROPERTY, key, rawClass));
8482
} else {
8583
//We need to skip the corresponding structure if property key was not found
86-
VALUE_SKIPPERS.getOrDefault(next, NOOP).accept(parser);
84+
VALUE_SKIPPERS.getOrDefault(parser.currentEvent(), NOOP).accept(parser);
8785
}
8886
break;
8987
case END_ARRAY:
9088
break;
9189
case END_OBJECT:
9290
return context.getInstance();
9391
default:
94-
throw new JsonbException("Unexpected state: " + next);
92+
throw new JsonbException("Unexpected state: " + parser.currentEvent());
9593
}
9694
}
9795
return context.getInstance();

src/main/java/org/eclipse/yasson/internal/deserializer/PositionChecker.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -71,11 +71,10 @@ private PositionChecker(Set<Event> expectedEvents,
7171

7272
@Override
7373
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
74-
Event original = context.getLastValueEvent();
74+
Event original = value.currentEvent();
7575
Event startEvent = original;
7676
if (!expectedEvents.contains(startEvent)) {
7777
startEvent = value.next();
78-
context.setLastValueEvent(startEvent);
7978
if (!expectedEvents.contains(startEvent)) {
8079
throw new JsonbException("Incorrect position for processing type: " + rType + ". "
8180
+ "Received event: " + original + " "
@@ -84,10 +83,10 @@ public Object deserialize(JsonParser value, DeserializationContextImpl context)
8483
}
8584
Object o = delegate.deserialize(value, context);
8685
if (CLOSING_EVENTS.containsKey(startEvent)
87-
&& CLOSING_EVENTS.get(startEvent) != context.getLastValueEvent()) {
86+
&& CLOSING_EVENTS.get(startEvent) != value.currentEvent()) {
8887
throw new JsonbException("Incorrect parser position after processing of the type: " + rType + ". "
8988
+ "Start event: " + startEvent + " "
90-
+ "After processing event: " + context.getLastValueEvent());
89+
+ "After processing event: " + value.currentEvent());
9190
}
9291
return o;
9392
}

0 commit comments

Comments
 (0)