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
Expand Up @@ -872,8 +872,11 @@ public void afterParsed(final Class<?> clazz) {

private boolean isReversedAdapter(final Class<?> payloadType, final Class<?> aClass, final Adapter<?, ?> instance) {
if (TypeAwareAdapter.class.isInstance(instance)) {
return payloadType.isAssignableFrom(Class.class.cast(TypeAwareAdapter.class.cast(instance).getTo()))
&& !payloadType.isAssignableFrom(Class.class.cast(TypeAwareAdapter.class.cast(instance).getFrom()));
final Class<?> to = toClass(TypeAwareAdapter.class.cast(instance).getTo());
final Class<?> from = toClass(TypeAwareAdapter.class.cast(instance).getFrom());
return to != null && from != null
&& payloadType.isAssignableFrom(to)
&& !payloadType.isAssignableFrom(from);
}
final Type[] genericInterfaces = aClass.getGenericInterfaces();
return Stream.of(genericInterfaces).filter(ParameterizedType.class::isInstance)
Expand All @@ -889,6 +892,16 @@ private boolean isReversedAdapter(final Class<?> payloadType, final Class<?> aCl
});
}

private Class<?> toClass(final Type type) {
if (Class.class.isInstance(type)) {
return Class.class.cast(type);
}
if (ParameterizedType.class.isInstance(type)) {
return toClass(ParameterizedType.class.cast(type).getRawType());
}
return null;
}

private boolean isNillable(final JsonbProperty property, final JsonbNillable propertyNillable, final JsonbNillable classOrPackageNillable) {
if (propertyNillable != null) {
return propertyNillable.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

Expand All @@ -42,41 +40,4 @@ public void assertRead(final Jsonb jsonb) {
assertEquals("test@domain.com:EmailClass.adaptFromJson", email.toString());
assertEquals("EmailClass.adaptFromJson", calls());
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void read() throws Exception {
super.read();
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void readAfterRead() throws Exception {
super.readAfterRead();
}

/**
* Fails as the adapter is not found on the first read
*/
@Test
@Ignore()
@Override
public void writeAfterRead() throws Exception {
super.writeAfterRead();
}

@Test
@Ignore()
@Override
public void readAfterWrite() throws Exception {
super.readAfterWrite();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -57,32 +55,4 @@ public void assertWrite(final Jsonb jsonb) {
assertEquals("[\"test\",\"domain.com\",\"Config.adaptToJson\"]", json);
assertEquals("Config.adaptToJson", calls());
}

@Test
@Ignore
@Override
public void read() throws Exception {
super.read();
}

@Test
@Ignore
@Override
public void readAfterRead() throws Exception {
super.readAfterRead();
}

@Test
@Ignore
@Override
public void readAfterWrite() throws Exception {
super.readAfterWrite();
}

@Test
@Ignore
@Override
public void writeAfterRead() throws Exception {
super.writeAfterRead();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import org.junit.Ignore;

import static org.junit.Assert.assertEquals;

@Ignore("java.lang.ClassCastException: Cannot cast sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to java.lang.Class")
public class MapAdapterOnClassDirectTest extends MapAdapterOnClassTest {

public Jsonb jsonb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

Expand All @@ -31,7 +29,7 @@
*
*
* Outcome:
* - Reads fail
* - Config wins on read
* - Config wins on write
*/
public class MapAdapterPrecedenceConfigClassDirectTest extends MapAdapterOnClassTest {
Expand All @@ -57,56 +55,4 @@ public void assertWrite(final Jsonb jsonb) {
assertEquals("{\"user\":\"test\",\"domain\":\"domain.com\",\"call\":\"Config.adaptToJson\"}", json);
assertEquals("Config.adaptToJson", calls());
}

/**
* java.lang.ClassCastException: Cannot cast sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to java.lang.Class
*
* at java.base/java.lang.Class.cast(Class.java:3889)
* at org.apache.johnzon.jsonb.JsonbAccessMode.isReversedAdapter(JsonbAccessMode.java:875)
*/
@Test
@Ignore
@Override
public void read() throws Exception {
super.read();
}

/**
* java.lang.ClassCastException: Cannot cast sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to java.lang.Class
*
* at java.base/java.lang.Class.cast(Class.java:3889)
* at org.apache.johnzon.jsonb.JsonbAccessMode.isReversedAdapter(JsonbAccessMode.java:875)
*/
@Test
@Ignore
@Override
public void readAfterRead() throws Exception {
super.readAfterRead();
}

/**
* java.lang.ClassCastException: Cannot cast sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to java.lang.Class
*
* at java.base/java.lang.Class.cast(Class.java:3889)
* at org.apache.johnzon.jsonb.JsonbAccessMode.isReversedAdapter(JsonbAccessMode.java:875)
*/
@Test
@Ignore
@Override
public void readAfterWrite() throws Exception {
super.readAfterWrite();
}

/**
* java.lang.ClassCastException: Cannot cast sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to java.lang.Class
*
* at java.base/java.lang.Class.cast(Class.java:3889)
* at org.apache.johnzon.jsonb.JsonbAccessMode.isReversedAdapter(JsonbAccessMode.java:875)
*/
@Test
@Ignore
@Override
public void writeAfterRead() throws Exception {
super.writeAfterRead();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

Expand All @@ -42,34 +40,4 @@ public void assertRead(final Jsonb jsonb) {
assertEquals("test@domain.com:EmailClass.adaptFromJson", email.toString());
assertEquals("EmailClass.adaptFromJson", calls());
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void read() throws Exception {
super.read();
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void readAfterRead() throws Exception {
super.readAfterRead();
}

/**
* Fails as the adapter is not found on the first read
*/
@Test
@Ignore()
@Override
public void writeAfterRead() throws Exception {
super.writeAfterRead();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry.builtin;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;

/**
* JSON-B 3.0 Section 3.4 — BigDecimal maps to JSON Number.
* I-JSON (RFC 7493 Section 2.2): values exceeding IEEE 754 double
* precision are serialized as strings. 1.5 fits in double → JSON Number.
*
* <p>Johnzon defaults to string adapter ON (non-spec). We explicitly
* disable it to test spec-compliant behavior.</p>
*
* @see ee.jakarta.tck.json.bind.defaultmapping.bignumbers.BigNumbersMappingTest
*/
public class BigDecimalDirectTest extends BuiltInSymmetryTest {

@Override
public Jsonb jsonb() {
return JsonbBuilder.create(new JsonbConfig()
.setProperty("johnzon.use-bigdecimal-stringadapter", false));
}

@Override
public void assertWrite(final Jsonb jsonb) {
assertEquals("1.5", jsonb.toJson(new BigDecimal("1.5")));
}

@Override
public void assertRead(final Jsonb jsonb) {
assertEquals(new BigDecimal("1.5"), jsonb.fromJson("1.5", BigDecimal.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry.builtin;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;

/**
* JSON-B 3.0 Section 3.4 — BigDecimal maps to JSON Number.
* I-JSON (RFC 7493 Section 2.2): values exceeding IEEE 754 double
* precision are serialized as strings. 1.5 fits in double → JSON Number.
*
* @see ee.jakarta.tck.json.bind.defaultmapping.bignumbers.BigNumbersMappingTest
*/
public class BigDecimalSimpleTest extends BuiltInSymmetryTest {

@Override
public Jsonb jsonb() {
return JsonbBuilder.create(new JsonbConfig()
.setProperty("johnzon.use-bigdecimal-stringadapter", false));
}

public static class Widget {

private BigDecimal value;

public BigDecimal getValue() {
return value;
}

public void setValue(final BigDecimal value) {
this.value = value;
}
}

@Override
public void assertWrite(final Jsonb jsonb) {
final Widget widget = new Widget();
widget.setValue(new BigDecimal("1.5"));
assertEquals("{\"value\":1.5}", jsonb.toJson(widget));
}

@Override
public void assertRead(final Jsonb jsonb) {
final Widget widget = jsonb.fromJson("{\"value\":1.5}", Widget.class);
assertEquals(new BigDecimal("1.5"), widget.getValue());
}
}
Loading
Loading