Skip to content

Commit 3c8ec09

Browse files
committed
handle nested types
1 parent f4e8e5c commit 3c8ec09

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ void write() throws IOException {
5353

5454
private void writeFactory() {
5555
if (genericParamsCount > 0) {
56+
57+
String typeName = adapterShortName;
58+
int nestedIndex = adapterShortName.indexOf("$");
59+
if (nestedIndex != -1) {
60+
typeName = typeName.substring(nestedIndex + 1);
61+
}
5662
writer.append(" public static final JsonAdapter.Factory Factory = (type, jsonb) -> {").eol();
57-
writer.append(" if (type instanceof ParameterizedType && Types.rawType(type) == %s.class) {", adapterShortName).eol();
63+
writer.append(" if (type instanceof ParameterizedType && Types.rawType(type) == %s.class) {", typeName).eol();
5864
writer.append(" Type[] args = Types.typeArguments(type);").eol();
5965
writer.append(" return new %sJsonAdapter(jsonb", adapterShortName);
6066
for (int i = 0; i < genericParamsCount; i++) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ void writeMetaInf() throws IOException {
5353
private void writeRegister() {
5454
writer.append(" @Override").eol();
5555
writer.append(" public void register(Jsonb.Builder builder) {").eol();
56-
List<String> strings = metaData.allFactories();
57-
for (String adapterFullName : strings) {
58-
String adapterShortName = Util.shortName(adapterFullName);
59-
String typeName = typeShortName(adapterShortName);
60-
writer.append(" builder.add(%sJsonAdapter.Factory);", typeName).eol();
56+
final List<String> strings = metaData.allFactories();
57+
for (final String adapterFullName : strings) {
58+
final String adapterShortName = Util.shortName(adapterFullName);
59+
final String typeName = typeShortName(adapterShortName);
60+
61+
writer.append(" builder.add(%s.Factory);", adapterShortName).eol();
6162
}
6263
for (String adapterFullName : metaData.all()) {
6364
String adapterShortName = Util.shortName(adapterFullName);

0 commit comments

Comments
 (0)