Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -31,7 +31,6 @@
*/
public class DeserializationContextImpl extends ProcessingContext implements DeserializationContext {
private final List<Runnable> delayedSetters = new ArrayList<>();
private JsonParser.Event lastValueEvent;
private Customization customization = ClassCustomization.empty();
private Object instance;

Expand All @@ -51,7 +50,6 @@ public DeserializationContextImpl(JsonbContext jsonbContext) {
*/
public DeserializationContextImpl(DeserializationContextImpl context) {
super(context.getJsonbContext());
this.lastValueEvent = context.lastValueEvent;
}

/**
Expand Down Expand Up @@ -81,24 +79,6 @@ public List<Runnable> getDeferredDeserializers() {
return delayedSetters;
}

/**
* Return last obtained {@link JsonParser.Event} event.
*
* @return last obtained event
*/
public JsonParser.Event getLastValueEvent() {
return lastValueEvent;
}

/**
* Set last obtained {@link JsonParser.Event} event.
*
* @param lastValueEvent last obtained event
*/
public void setLastValueEvent(JsonParser.Event lastValueEvent) {
this.lastValueEvent = lastValueEvent;
}

/**
* Return customization used by currently processed user defined deserializer.
*
Expand Down Expand Up @@ -130,9 +110,10 @@ public <T> T deserialize(Type type, JsonParser parser) {
@SuppressWarnings("unchecked")
private <T> T deserializeItem(Type type, JsonParser parser) {
try {
if (lastValueEvent == null) {
lastValueEvent = parser.next();
checkState();
JsonParser.Event startingEvent = parser.currentEvent();
if (startingEvent == null || startingEvent == JsonParser.Event.KEY_NAME) {
parser.next();
checkState(parser);
}
ModelDeserializer<JsonParser> modelDeserializer = getJsonbContext().getChainModelCreator().deserializerChain(type);
return (T) modelDeserializer.deserialize(parser, this);
Expand All @@ -143,8 +124,8 @@ private <T> T deserializeItem(Type type, JsonParser parser) {
}
}

private void checkState() {
if (lastValueEvent == JsonParser.Event.KEY_NAME) {
private void checkState(JsonParser parser) {
if (parser.currentEvent() == JsonParser.Event.KEY_NAME) {
throw new JsonbException("JsonParser has incorrect position as the first event: KEY_NAME");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -35,9 +35,7 @@ class ArrayDeserializer implements ModelDeserializer<JsonParser> {
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
Collection<Object> collection = new ArrayList<>();
while (parser.hasNext()) {
final JsonParser.Event next = parser.next();
context.setLastValueEvent(next);
switch (next) {
switch (parser.next()) {
case START_OBJECT:
case START_ARRAY:
case VALUE_STRING:
Expand All @@ -51,7 +49,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
case END_ARRAY:
return collection;
default:
throw new JsonbException("Unexpected state: " + next);
throw new JsonbException("Unexpected state: " + parser.currentEvent());
}
}
return collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -35,9 +35,7 @@ class CollectionDeserializer implements ModelDeserializer<JsonParser> {
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
Collection<Object> collection = (Collection<Object>) context.getInstance();
while (parser.hasNext()) {
final JsonParser.Event next = parser.next();
context.setLastValueEvent(next);
switch (next) {
switch (parser.next()) {
case VALUE_NULL:
case START_OBJECT:
case START_ARRAY:
Expand All @@ -51,7 +49,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
case END_ARRAY:
return collection;
default:
throw new JsonbException("Unexpected state: " + next);
throw new JsonbException("Unexpected state: " + parser.currentEvent());
}
}
return collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -33,8 +33,6 @@ class ContextSwitcher implements ModelDeserializer<JsonParser> {
@Override
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
DeserializationContextImpl ctx = new DeserializationContextImpl(context);
Object returnedValue = delegate.deserialize(modelDeserializer.deserialize(value, ctx), context);
context.setLastValueEvent(ctx.getLastValueEvent());
return returnedValue;
return delegate.deserialize(modelDeserializer.deserialize(value, ctx), context);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -23,8 +23,6 @@
import org.eclipse.yasson.internal.jsonstructure.JsonStructureToParserAdapter;
import org.eclipse.yasson.internal.model.customization.TypeInheritanceConfiguration;

import static jakarta.json.stream.JsonParser.Event;

/**
* Instance creator following the inheritance structure defined by {@link jakarta.json.bind.annotation.JsonbTypeInfo}.
*/
Expand Down Expand Up @@ -58,8 +56,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
.build();
jsonParser = new JsonStructureToParserAdapter(newJsonObject);
//To get to the first event
Event event = jsonParser.next();
context.setLastValueEvent(event);
jsonParser.next();
Class<?> polymorphicTypeClass;
if (alias == null) {
return defaultProcessor.deserialize(jsonParser, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -68,9 +68,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
String key = null;
Map<String, Object> paramValues = new HashMap<>();
while (parser.hasNext()) {
final JsonParser.Event next = parser.next();
context.setLastValueEvent(next);
switch (next) {
switch (parser.next()) {
case KEY_NAME:
key = renamer.apply(parser.getString());
break;
Expand All @@ -94,7 +92,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
throw new JsonbException(Messages.getMessage(MessageKeys.UNKNOWN_JSON_PROPERTY, key, clazz));
} else {
//We need to skip the corresponding structure if property key was not found
VALUE_SKIPPERS.getOrDefault(next, NOOP).accept(parser);
VALUE_SKIPPERS.getOrDefault(parser.currentEvent(), NOOP).accept(parser);
}
break;
case END_OBJECT:
Expand All @@ -112,7 +110,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
context.getDeferredDeserializers().clear();
return context.getInstance();
default:
throw new JsonbException("Unexpected state: " + next);
throw new JsonbException("Unexpected state: " + parser.currentEvent());
}
}
return context.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -43,9 +43,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
Mode mode = Mode.NONE;
State state = State.NEXT;
while (parser.hasNext()) {
final JsonParser.Event next = parser.next();
context.setLastValueEvent(next);
switch (next) {
switch (parser.next()) {
case KEY_NAME:
mode = mode == Mode.NONE ? Mode.NORMAL : mode;
if (mode == Mode.NORMAL) {
Expand Down Expand Up @@ -89,7 +87,7 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
case END_ARRAY:
return map;
default:
throw new JsonbException("Unexpected state: " + next);
throw new JsonbException("Unexpected state: " + parser.currentEvent());
}
}
return map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -42,7 +42,7 @@ public NullCheckDeserializer(ModelDeserializer<JsonParser> nonNullDeserializer,

@Override
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
if (context.getLastValueEvent() != JsonParser.Event.VALUE_NULL) {
if (value.currentEvent() != JsonParser.Event.VALUE_NULL) {
return nonNullDeserializer.deserialize(value, context);
}
return nullDeserializer.deserialize(null, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ class ObjectDeserializer implements ModelDeserializer<JsonParser> {
public Object deserialize(JsonParser parser, DeserializationContextImpl context) {
String key = null;
while (parser.hasNext()) {
final JsonParser.Event next = parser.next();
context.setLastValueEvent(next);
switch (next) {
switch (parser.next()) {
case KEY_NAME:
key = renamer.apply(parser.getString());
break;
Expand All @@ -83,15 +81,15 @@ public Object deserialize(JsonParser parser, DeserializationContextImpl context)
throw new JsonbException(Messages.getMessage(MessageKeys.UNKNOWN_JSON_PROPERTY, key, rawClass));
} else {
//We need to skip the corresponding structure if property key was not found
VALUE_SKIPPERS.getOrDefault(next, NOOP).accept(parser);
VALUE_SKIPPERS.getOrDefault(parser.currentEvent(), NOOP).accept(parser);
}
break;
case END_ARRAY:
break;
case END_OBJECT:
return context.getInstance();
default:
throw new JsonbException("Unexpected state: " + next);
throw new JsonbException("Unexpected state: " + parser.currentEvent());
}
}
return context.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -71,11 +71,10 @@ private PositionChecker(Set<Event> expectedEvents,

@Override
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
Event original = context.getLastValueEvent();
Event original = value.currentEvent();
Event startEvent = original;
if (!expectedEvents.contains(startEvent)) {
startEvent = value.next();
context.setLastValueEvent(startEvent);
if (!expectedEvents.contains(startEvent)) {
throw new JsonbException("Incorrect position for processing type: " + rType + ". "
+ "Received event: " + original + " "
Expand All @@ -84,10 +83,10 @@ public Object deserialize(JsonParser value, DeserializationContextImpl context)
}
Object o = delegate.deserialize(value, context);
if (CLOSING_EVENTS.containsKey(startEvent)
&& CLOSING_EVENTS.get(startEvent) != context.getLastValueEvent()) {
&& CLOSING_EVENTS.get(startEvent) != value.currentEvent()) {
throw new JsonbException("Incorrect parser position after processing of the type: " + rType + ". "
+ "Start event: " + startEvent + " "
+ "After processing event: " + context.getLastValueEvent());
+ "After processing event: " + value.currentEvent());
}
return o;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -65,10 +65,9 @@ public Object deserialize(JsonParser value, DeserializationContextImpl context)
// return exactType.deserialize(value, newContext);
// }
// newContext.getUserProcessorChain().add(userDefinedDeserializer.getClass());
YassonParser yassonParser = new YassonParser(value, context.getLastValueEvent(), newContext);
YassonParser yassonParser = new YassonParser(value, value.currentEvent());
Object object = userDefinedDeserializer.deserialize(yassonParser, newContext, rType);
yassonParser.skipRemaining();
context.setLastValueEvent(newContext.getLastValueEvent());
return delegate.deserialize(object, context);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -36,7 +36,7 @@ public ValueExtractor(TypeDeserializer delegate) {

@Override
public Object deserialize(JsonParser value, DeserializationContextImpl context) {
JsonParser.Event last = context.getLastValueEvent();
JsonParser.Event last = value.currentEvent();
switch (last) {
case VALUE_TRUE:
return delegate.deserialize(Boolean.TRUE, context);
Expand Down
Loading