This commit is contained in:
Looly
2024-09-24 00:35:58 +08:00
parent 4afb8c581e
commit 1b92f58bae
32 changed files with 554 additions and 374 deletions

View File

@@ -33,10 +33,7 @@ public class CustomSerializeTest {
public void init() {
TypeAdapterManager.getInstance().register(CustomBean.class,
(JSONSerializer<CustomBean>) (bean, context) ->{
JSONObject contextJson = (JSONObject) context.getContextJson();
if(null == contextJson){
contextJson = JSONUtil.ofObj(context.config());
}
final JSONObject contextJson = context.getOrCreateObj();
return contextJson.set("customName", bean.name);
});
}

View File

@@ -57,7 +57,7 @@ public class Issue2555Test {
public static class MySerializer implements JSONSerializer<MyType> {
@Override
public JSON serialize(final MyType bean, final JSONContext context) {
return ((JSONObject)context.getContextJson()).set("addr", bean.getAddress());
return context.getOrCreateObj().set("addr", bean.getAddress());
}
}

View File

@@ -70,12 +70,7 @@ public class Issue3086Test {
public JSON serialize(final TestBean bean, final JSONContext context) {
final List<String> strings = bean.getAuthorities()
.stream().map(SimpleGrantedAuthority::getAuthority).collect(Collectors.toList());
JSONObject contextJson = (JSONObject) context.getContextJson();
if(null == contextJson){
contextJson = new JSONObject(context.config());
}
contextJson.set("authorities",strings);
return contextJson;
return context.getOrCreateObj().set("authorities",strings);
}
}
}