Skip to content

Commit

Permalink
fix JSONField#deserializeUsing not work on ListField
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 27, 2024
1 parent 6a3a1d4 commit e3cd07f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,7 @@ private <T> int genReadFieldValue(
}

boolean list = List.class.isAssignableFrom(fieldClass)
&& fieldReader.getInitReader() == null
&& !fieldClass.getName().startsWith("com.google.common.collect.Immutable");

if (list) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.alibaba.fastjson2.issues_2200;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.reader.ObjectReader;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Type;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class Issue2213 {
@Test
public void test() {
assertThrows(
JSONException.class,
() -> JSON.parseObject("{\"values\":[1]}", TextEntity.class, JSONReader.Feature.FieldBased));
}

public static class ListIntReader
implements ObjectReader<Object> {
public static final ListIntReader INSTANCE = new ListIntReader();

@Override
public Object readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
throw new JSONException("TODO");
}
}

private class TextEntity {
@JSONField(deserializeUsing = ListIntReader.class, serializeUsing = ListIntReader.class)
public List<Integer> values;
}
}

0 comments on commit e3cd07f

Please sign in to comment.