Skip to content

Commit 3b3e326

Browse files
committed
Merge branch 'feature/add-bom' of github.com:avaje/avaje-jsonb into feature/add-bom
2 parents b9466d1 + 149a860 commit 3b3e326

File tree

39 files changed

+192
-1470
lines changed

39 files changed

+192
-1470
lines changed

blackbox-test/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.avaje</groupId>
66
<artifactId>avaje-jsonb-parent</artifactId>
7-
<version>3.1-RC1</version>
7+
<version>3.1-RC3</version>
88
</parent>
99

1010
<artifactId>blackbox-test</artifactId>
@@ -28,13 +28,13 @@
2828
<dependency>
2929
<groupId>io.avaje</groupId>
3030
<artifactId>avaje-jsonb</artifactId>
31-
<version>3.1-RC1</version>
31+
<version>3.1-RC3</version>
3232
</dependency>
3333

3434
<dependency>
3535
<groupId>io.avaje</groupId>
3636
<artifactId>avaje-json-node</artifactId>
37-
<version>3.1-RC1</version>
37+
<version>3.1-RC3</version>
3838
</dependency>
3939

4040
<!-- <dependency>-->
@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>io.avaje</groupId>
5656
<artifactId>avaje-jsonb-generator</artifactId>
57-
<version>3.1-RC1</version>
57+
<version>3.1-RC3</version>
5858
<scope>provided</scope>
5959
</dependency>
6060
<dependency>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.customer.datetime;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.util.Calendar;
6+
7+
@Json
8+
public record MyCalData(Calendar cal) {
9+
}

blackbox-test/src/main/java/org/example/customer/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Json.Import(MyOtherClass.class)
1+
@Json.Import({MyOtherClass.class}) //, java.util.Calendar.class})
22
package org.example.customer;
33

44
import io.avaje.jsonb.Json;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.example.customer.datetime;
2+
3+
import io.avaje.jsonb.JsonType;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.time.ZoneId;
8+
import java.time.ZonedDateTime;
9+
import java.util.GregorianCalendar;
10+
import java.util.TimeZone;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
class CalendarTest {
15+
16+
@Test
17+
void calendarAsEpochMillis() {
18+
Jsonb jsonb = Jsonb.builder().calendarAsString(false).build();
19+
JsonType<MyCalData> type = jsonb.type(MyCalData.class);
20+
21+
var zdt = ZonedDateTime.of(2001, 3, 23, 0, 1, 2, 0, ZoneId.of("Pacific/Auckland"));
22+
var calendar = GregorianCalendar.from(zdt);
23+
var data = new MyCalData(calendar);
24+
var asJson = type.toJson(data);
25+
var fromJson = type.fromJson(asJson);
26+
27+
assertThat(fromJson.cal().toInstant()).isEqualTo(data.cal().toInstant());
28+
// deserialized as UTC
29+
assertThat(fromJson.cal().getTimeZone()).isEqualTo(TimeZone.getTimeZone(ZoneId.of("UTC")));
30+
}
31+
32+
@Test
33+
void calendarAsString() {
34+
Jsonb jsonb = Jsonb.builder().calendarAsString(true).build();
35+
JsonType<MyCalData> type = jsonb.type(MyCalData.class);
36+
37+
var zdt = ZonedDateTime.of(2001, 3, 23, 0, 1, 2, 0, ZoneId.of("Pacific/Auckland"));
38+
// note calendar deserialized using ISO8601 with
39+
// setFirstDayOfWeek(MONDAY) and setMinimalDaysInFirstWeek(4);
40+
var calendar = GregorianCalendar.from(zdt);
41+
var data = new MyCalData(calendar);
42+
var asJson = type.toJson(data);
43+
var fromJson = type.fromJson(asJson);
44+
45+
assertThat(fromJson.cal().toInstant()).isEqualTo(data.cal().toInstant());
46+
assertThat(fromJson.cal().getTimeZone()).isEqualTo(data.cal().getTimeZone());
47+
assertThat(fromJson.cal().getFirstDayOfWeek()).isEqualTo(data.cal().getFirstDayOfWeek());
48+
assertThat(fromJson.cal().getMinimalDaysInFirstWeek()).isEqualTo(data.cal().getMinimalDaysInFirstWeek());
49+
assertThat(fromJson).isEqualTo(data);
50+
}
51+
}

json-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.avaje</groupId>
88
<artifactId>avaje-jsonb-parent</artifactId>
9-
<version>3.1-RC1</version>
9+
<version>3.1-RC3</version>
1010
</parent>
1111

1212
<artifactId>avaje-json-core</artifactId>

json-node/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.avaje</groupId>
88
<artifactId>avaje-jsonb-parent</artifactId>
9-
<version>3.1-RC1</version>
9+
<version>3.1-RC3</version>
1010
</parent>
1111

1212
<artifactId>avaje-json-node</artifactId>
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>io.avaje</groupId>
2626
<artifactId>avaje-json-core</artifactId>
27-
<version>3.1-RC1</version>
27+
<version>3.1-RC3</version>
2828
</dependency>
2929

3030
<dependency>

jsonb-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.avaje</groupId>
66
<artifactId>avaje-jsonb-parent</artifactId>
7-
<version>3.1-RC1</version>
7+
<version>3.1-RC3</version>
88
</parent>
99

1010
<artifactId>avaje-jsonb-generator</artifactId>

jsonb-generator/src/main/java/io/avaje/jsonb/generator/ClassReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ final class ClassReader implements BeanReader {
4343
/** An Interface/abstract type with a single implementation */
4444
private ClassReader implementation;
4545

46-
ClassReader(TypeElement beanType) {
47-
this(beanType, null);
46+
ClassReader(TypeElement beanType, String errorContext) {
47+
this(beanType, null, errorContext);
4848
}
4949

50-
ClassReader(TypeElement beanType, TypeElement mixInElement) {
50+
ClassReader(TypeElement beanType, TypeElement mixInElement, String errorContext) {
5151
this.beanType = beanType;
5252
this.type = beanType.getQualifiedName().toString();
5353
this.shortName = shortName(beanType);
5454
final NamingConventionReader ncReader = new NamingConventionReader(beanType);
5555
this.namingConvention = ncReader.get();
5656
this.typeProperty = ncReader.typeProperty();
5757
this.caseInsensitiveKeys = ncReader.isCaseInsensitiveKeys();
58-
this.typeReader = new TypeReader(beanType, mixInElement, namingConvention, typePropertyKey());
58+
this.typeReader = new TypeReader(errorContext, beanType, mixInElement, namingConvention, typePropertyKey());
5959
typeReader.process();
6060
this.nonAccessibleField = typeReader.nonAccessibleField();
6161
this.hasSubTypes = typeReader.hasSubTypes();
@@ -94,7 +94,7 @@ boolean isRecord(TypeElement beanType) {
9494
* For an interface type set the single implementation to use for fromJson().
9595
*/
9696
void setImplementationType(TypeElement implementationType) {
97-
this.implementation = new ClassReader(implementationType);
97+
this.implementation = new ClassReader(implementationType, "");
9898
}
9999

100100
@Override

jsonb-generator/src/main/java/io/avaje/jsonb/generator/JsonbProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ private void readModule() {
9090

9191
@Override
9292
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {
93+
if (round.errorRaised()) {
94+
return false;
95+
}
9396
APContext.setProjectModuleElement(annotations, round);
9497
readModule();
9598
getElements(round, ValuePrism.PRISM_TYPE).ifPresent(this::writeValueAdapters);
@@ -315,19 +318,19 @@ private void writeAdapterForType(TypeElement typeElement) {
315318
if (valueElements.contains(typeElement.toString())) {
316319
return;
317320
}
318-
writeAdapter(typeElement, new ClassReader(typeElement));
321+
writeAdapter(typeElement, new ClassReader(typeElement, ""));
319322
}
320323

321324
private void writeAdapterForImportedType(TypeElement importedType, TypeElement implementationType) {
322-
final ClassReader beanReader = new ClassReader(importedType);
325+
final ClassReader beanReader = new ClassReader(importedType, "@Json.Import of ");
323326
if (implementationType != null) {
324327
beanReader.setImplementationType(implementationType);
325328
}
326329
writeAdapter(importedType, beanReader);
327330
}
328331

329332
private void writeAdapterForMixInType(TypeElement typeElement, TypeElement mixin) {
330-
final ClassReader beanReader = new ClassReader(typeElement, mixin);
333+
final ClassReader beanReader = new ClassReader(typeElement, mixin, "@Json.Mixin of ");
331334
writeAdapter(typeElement, beanReader);
332335
}
333336

jsonb-generator/src/main/java/io/avaje/jsonb/generator/TypeReader.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ final class TypeReader {
3636
private final List<String> genericTypeParams;
3737
private final NamingConvention namingConvention;
3838
private final boolean hasJsonAnnotation;
39+
private final String errorContext;
3940
private MethodReader constructor;
4041
private boolean defaultPublicConstructor;
4142
private final Map<String, MethodReader.MethodParam> constructorParamMap = new LinkedHashMap<>();
@@ -56,7 +57,8 @@ final class TypeReader {
5657

5758
private final boolean hasJsonCreator;
5859

59-
TypeReader(TypeElement baseType, TypeElement mixInType, NamingConvention namingConvention, String typePropertyKey) {
60+
TypeReader(String errorContext, TypeElement baseType, TypeElement mixInType, NamingConvention namingConvention, String typePropertyKey) {
61+
this.errorContext = errorContext;
6062
this.baseType = baseType;
6163
this.genericTypeParams = initTypeParams(baseType);
6264
Optional<ExecutableElement> jsonCreator = Optional.empty();
@@ -263,7 +265,7 @@ private void readMethod(Element element, List<FieldReader> localFields) {
263265
// for getter/accessor methods only, not setters
264266
PropertyPrism.getOptionalOn(methodElement).ifPresent(propertyPrism -> {
265267
if (!methodElement.getParameters().isEmpty()) {
266-
logError("Json.Property can only be placed on Getter Methods, but on %s", methodElement);
268+
logError(errorContext + baseType + ", @Json.Property can only be placed on Getter Methods, but on %s", methodElement);
267269
return;
268270
}
269271

@@ -302,7 +304,7 @@ private void matchFieldToSetter(FieldReader field) {
302304
if (isCollectionType(field.type())) {
303305
field.setUseGetterAddAll();
304306
} else {
305-
logError("Non public field " + baseType + " " + field.fieldName() + " with no matching setter or constructor?");
307+
logError(errorContext + baseType + ", non public field " + field.fieldName() + " with no matching setter or constructor?");
306308
}
307309
}
308310
}
@@ -386,14 +388,9 @@ private void matchFieldToGetter(FieldReader field) {
386388
&& !field.isSubTypeField()) {
387389
nonAccessibleField = true;
388390
if (hasJsonAnnotation) {
389-
logError(
390-
"Non accessible field "
391-
+ baseType
392-
+ " "
393-
+ field.fieldName()
394-
+ " with no matching getter?");
391+
logError(errorContext + baseType + ", non accessible field " + field.fieldName() + " with no matching getter?");
395392
} else {
396-
logNote("Non accessible field " + baseType + " " + field.fieldName());
393+
logNote(errorContext + baseType + ", non accessible field " + field.fieldName());
397394
}
398395
}
399396
}

jsonb-inject-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>avaje-jsonb-parent</artifactId>
88
<groupId>io.avaje</groupId>
9-
<version>3.1-RC1</version>
9+
<version>3.1-RC3</version>
1010
</parent>
1111

1212
<artifactId>avaje-jsonb-inject-plugin</artifactId>

jsonb-jackson/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>avaje-jsonb-parent</artifactId>
66
<groupId>io.avaje</groupId>
7-
<version>3.1-RC1</version>
7+
<version>3.1-RC3</version>
88
</parent>
99

1010
<artifactId>avaje-jsonb-jackson</artifactId>

jsonb-jakarta/pom.xml

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)