Skip to content

Commit

Permalink
[eclipse-ee4j#617] First corrections after review
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Feb 13, 2024
1 parent 49018c1 commit 5ad157e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ JsonbCreator createJsonbCreator(Executable executable, JsonbCreator existing, Cl
expectedClass.ifPresent(clazz -> {
if (!ReflectionUtils.getRawType(adapterBinding.getBindingType()).isAssignableFrom(clazz)) {
throw new JsonbException(Messages.getMessage(MessageKeys.ADAPTER_INCOMPATIBLE,
adapterBinding.getBindingType(),
clazz));
adapterBinding.getBindingType(), clazz));
}
});
return adapterBinding;
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/org/eclipse/yasson/internal/JsonBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;

import jakarta.json.JsonStructure;
import jakarta.json.bind.JsonbConfig;
Expand Down Expand Up @@ -54,51 +53,51 @@ public class JsonBinding implements YassonJsonb {
}
}

private <T> T deserialize(final Type type, final Supplier<JsonParser> parserSupplier) {
Objects.requireNonNull(parserSupplier);
try (JsonParser parser = parserSupplier.get()) {
private <T> T deserialize(final Type type, final JsonParser parser) {
Objects.requireNonNull(parser);
try (parser) {
return new DeserializationContextImpl(jsonbContext).deserialize(type, parser);
}
}

@Override
public <T> T fromJson(String str, Class<T> type) throws JsonbException {
return deserialize(type, () -> jsonbContext.getJsonProvider().createParser(new StringReader(str)));
return deserialize(type, jsonbContext.getJsonProvider().createParser(new StringReader(str)));
}

@Override
public <T> T fromJson(String str, Type type) throws JsonbException {
return deserialize(type, () -> jsonbContext.getJsonProvider().createParser(new StringReader(str)));
return deserialize(type, jsonbContext.getJsonProvider().createParser(new StringReader(str)));
}

@Override
public <T> T fromJson(Reader reader, Class<T> type) throws JsonbException {
return deserialize(type, () -> jsonbContext.getJsonProvider().createParser(reader));
return deserialize(type, jsonbContext.getJsonProvider().createParser(reader));
}

@Override
public <T> T fromJson(Reader reader, Type type) throws JsonbException {
return deserialize(type, () -> jsonbContext.getJsonProvider().createParser(reader));
return deserialize(type, jsonbContext.getJsonProvider().createParser(reader));
}

@Override
public <T> T fromJson(InputStream stream, Class<T> clazz) throws JsonbException {
return deserialize(clazz, () -> inputStreamParser(stream));
return deserialize(clazz, inputStreamParser(stream));
}

@Override
public <T> T fromJson(InputStream stream, Type type) throws JsonbException {
return deserialize(type, () -> inputStreamParser(stream));
return deserialize(type, inputStreamParser(stream));
}

@Override
public <T> T fromJsonStructure(JsonStructure jsonStructure, Class<T> type) throws JsonbException {
return deserialize(type, () -> new JsonStructureToParserAdapter(jsonStructure, jsonbContext.getJsonProvider()));
return deserialize(type, new JsonStructureToParserAdapter(jsonStructure, jsonbContext.getJsonProvider()));
}

@Override
public <T> T fromJsonStructure(JsonStructure jsonStructure, Type runtimeType) throws JsonbException {
return deserialize(runtimeType, () -> new JsonStructureToParserAdapter(jsonStructure, jsonbContext.getJsonProvider()));
return deserialize(runtimeType, new JsonStructureToParserAdapter(jsonStructure, jsonbContext.getJsonProvider()));
}

private JsonParser inputStreamParser(InputStream stream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

public class NumberAdapter implements JsonbAdapter<Number, String> {

private final static Counter counter = new Counter();
private final static Counter COUNTER = new Counter();

public static Counter getCounter() {
return counter;
return COUNTER;
}

{
counter.add();
COUNTER.add();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

public class NumberDeserializer implements JsonbDeserializer<Number> {

private final static Counter counter = new Counter();
private final static Counter COUNTER = new Counter();

public static Counter getCounter() {
return counter;
return COUNTER;
}

{
counter.add();
COUNTER.add();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

public class NumberSerializer implements JsonbSerializer<Number> {

private final static Counter counter = new Counter();
private final static Counter COUNTER = new Counter();

public static Counter getCounter() {
return counter;
return COUNTER;
}

{
counter.add();
COUNTER.add();
}

@Override
Expand Down

0 comments on commit 5ad157e

Please sign in to comment.