Skip to content

Commit c375aef

Browse files
authored
Merge pull request #106 from SentryMan/interface-adapter
Make JsonAdapter an Interface
2 parents 8168ca3 + fe6b1db commit c375aef

File tree

20 files changed

+59
-50
lines changed

20 files changed

+59
-50
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.example.customer;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
@Json
6+
public record ErrorResponse(String id, String text) {}

blackbox-test/src/main/java/org/example/customer/customtype/CustomTypeComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void register(Jsonb.Builder builder) {
1313
builder.add(MyCustomScalarType.class, new CustomTypeAdapterWithStar().nullSafe());
1414
}
1515

16-
static class CustomTypeAdapterWithStar extends JsonAdapter<MyCustomScalarType> {
16+
static class CustomTypeAdapterWithStar implements JsonAdapter<MyCustomScalarType> {
1717

1818
@Override
1919
public void toJson(JsonWriter writer, MyCustomScalarType value) {

blackbox-test/src/test/java/org/example/customer/customtype/CustomScalarTypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void toJson_fromJson() {
5050
assertThat(wrapper1.custom()).isEqualTo(wrapper.custom());
5151
}
5252

53-
static class CustomTypeAdapter extends JsonAdapter<MyCustomScalarType> {
53+
static class CustomTypeAdapter implements JsonAdapter<MyCustomScalarType> {
5454

5555
@Override
5656
public void toJson(JsonWriter writer, MyCustomScalarType value) {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.avaje.jsonb.generator;
22

3-
import static io.avaje.jsonb.generator.ProcessingContext.*;
4-
import javax.tools.JavaFileObject;
3+
import static io.avaje.jsonb.generator.ProcessingContext.createWriter;
4+
55
import java.io.IOException;
66
import java.io.Writer;
77

8+
import javax.tools.JavaFileObject;
9+
810
final class SimpleAdapterWriter {
911

1012
private final BeanReader beanReader;
@@ -17,7 +19,7 @@ final class SimpleAdapterWriter {
1719

1820
SimpleAdapterWriter(BeanReader beanReader) {
1921
this.beanReader = beanReader;
20-
AdapterName adapterName = new AdapterName(beanReader.getBeanType());
22+
final AdapterName adapterName = new AdapterName(beanReader.getBeanType());
2123
this.adapterShortName = adapterName.shortName();
2224
this.adapterPackage = adapterName.adapterPackage();
2325
this.adapterFullName = adapterName.fullName();
@@ -29,7 +31,7 @@ String fullName() {
2931
}
3032

3133
private Writer createFileWriter() throws IOException {
32-
JavaFileObject jfo = createWriter(adapterFullName);
34+
final JavaFileObject jfo = createWriter(adapterFullName);
3335
return jfo.openWriter();
3436
}
3537

@@ -53,7 +55,7 @@ void write() throws IOException {
5355
private void writeFactory() {
5456
if (genericParamsCount > 0) {
5557
String typeName = adapterShortName;
56-
int nestedIndex = adapterShortName.indexOf("$");
58+
final int nestedIndex = adapterShortName.indexOf("$");
5759
if (nestedIndex != -1) {
5860
typeName = typeName.substring(nestedIndex + 1);
5961
}
@@ -107,9 +109,9 @@ private void writeClassEnd() {
107109

108110
private void writeClassStart() {
109111
writer.append("@Generated").eol();
110-
writer.append("public final class %sJsonAdapter extends JsonAdapter<%s> ", adapterShortName, beanReader.shortName());
112+
writer.append("public final class %sJsonAdapter implements JsonAdapter<%s> ", adapterShortName, beanReader.shortName());
111113
if (!beanReader.hasSubtypes()) {
112-
writer.append("implements ViewBuilderAware ");
114+
writer.append(", ViewBuilderAware ");
113115
}
114116
writer.append("{").eol().eol();
115117
}

jsonb-jackson/src/test/java/org/example/AddressJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import java.lang.invoke.MethodHandle;
1212

13-
public class AddressJsonAdapter extends JsonAdapter<Address> implements ViewBuilderAware {
13+
public class AddressJsonAdapter implements JsonAdapter<Address>, ViewBuilderAware {
1414

1515
private final JsonAdapter<String> stringAdapter;
1616
private final PropertyNames names;

jsonb-jackson/src/test/java/org/example/ContactJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.lang.invoke.MethodHandle;
1111

12-
public class ContactJsonAdapter extends JsonAdapter<Contact> implements ViewBuilderAware {
12+
public class ContactJsonAdapter implements JsonAdapter<Contact>, ViewBuilderAware {
1313

1414
private final JsonAdapter<Long> longAdapter;
1515
private final JsonAdapter<String> stringAdapter;

jsonb-jackson/src/test/java/org/example/CustomerJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.time.Instant;
1010
import java.util.List;
1111

12-
public class CustomerJsonAdapter extends JsonAdapter<Customer> implements ViewBuilderAware {
12+
public class CustomerJsonAdapter implements JsonAdapter<Customer>, ViewBuilderAware {
1313

1414
private final JsonAdapter<Integer> intAdapter;
1515
private final JsonAdapter<String> stringAdapter;

jsonb-jackson/src/test/java/org/example/MyBasicJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.lang.invoke.MethodHandle;
1313

1414
@Generated
15-
public final class MyBasicJsonAdapter extends JsonAdapter<StreamBasicTest.MyBasic> implements ViewBuilderAware {
15+
public final class MyBasicJsonAdapter implements JsonAdapter<StreamBasicTest.MyBasic>, ViewBuilderAware {
1616

1717
// naming convention Match
1818
// id [int] name:id constructor

jsonb-jackson/src/test/java/org/example/MyEnumJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import io.avaje.jsonb.spi.Generated;
1313

1414
@Generated
15-
public final class MyEnumJsonAdapter extends JsonAdapter<MyEnum> {
15+
public final class MyEnumJsonAdapter implements JsonAdapter<MyEnum> {
1616

1717
private static final Map<MyEnum, String> toValue = new EnumMap<>(MyEnum.class);
1818
private static final Map<String, MyEnum> toEnum = new HashMap<>();

jsonb-jackson/src/test/java/org/example/MyIntEnumJsonAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import io.avaje.jsonb.JsonWriter;
1111
import io.avaje.jsonb.Jsonb;
1212

13-
public final class MyIntEnumJsonAdapter extends JsonAdapter<MyIntEnum> {
13+
public final class MyIntEnumJsonAdapter implements JsonAdapter<MyIntEnum> {
1414

1515
private static final Map<MyIntEnum, Integer> toValue = new EnumMap<>(MyIntEnum.class);
1616
private static final Map<Integer, MyIntEnum> toEnum = new HashMap<>();

0 commit comments

Comments
 (0)