mirror of https://github.com/alibaba/fastjson2.git
Solon upgraded to v3.6.0 (#3810)
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (11, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (17, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (21, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (25, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:arm64 os:macos-latest]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:arm64 os:ubuntu-24.04-arm]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:x64 os:ubuntu-24.04]) (push) Has been cancelled
Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os-arch.os }} (${{ matrix.os-arch.arch }}) (8, map[arch:x64 os:windows-latest]) (push) Has been cancelled
Details
* solon upgraded to v3.2.0 * solon upgraded to v3.4.2 * solon upgraded to v3.6.0 * solon upgraded to v3.6.0
This commit is contained in:
parent
62c2cc9f46
commit
4ab8394e14
|
@ -1,7 +1,6 @@
|
|||
package com.alibaba.fastjson2.example.solontest.config;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2ActionExecutor;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2StringSerializer;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
|
||||
|
@ -12,12 +11,12 @@ import org.noear.solon.annotation.Configuration;
|
|||
@Configuration
|
||||
public class JsonConfigurer {
|
||||
@Bean
|
||||
public void fastjson2(Fastjson2ActionExecutor executor, Fastjson2RenderFactory render) {
|
||||
// executor.config().config(
|
||||
public void fastjson2(Fastjson2StringSerializer serializer) {
|
||||
// serializer.getDeserializeConfig().addFeatures(
|
||||
// JSONReader.Feature.FieldBased,
|
||||
// JSONReader.Feature.SupportArrayToBean);
|
||||
//
|
||||
// render.addFeatures(
|
||||
// serializer.getSerializeConfig().addFeatures(
|
||||
// JSONWriter.Feature.WriteMapNullValue,
|
||||
// JSONWriter.Feature.PrettyFormat);
|
||||
}
|
||||
|
|
|
@ -1,62 +1,42 @@
|
|||
package com.alibaba.fastjson2.support.solon;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.*;
|
||||
import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.mvc.ActionExecuteHandlerDefault;
|
||||
import org.noear.solon.core.util.Assert;
|
||||
import org.noear.solon.core.util.LazyReference;
|
||||
import org.noear.solon.core.wrap.MethodWrap;
|
||||
import org.noear.solon.core.wrap.ParamWrap;
|
||||
import org.noear.solon.serialization.AbstractStringEntityConverter;
|
||||
import org.noear.solon.serialization.SerializerNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Json ActionExecuteHandler
|
||||
* Fastjson2 EntityConverter
|
||||
*
|
||||
* @author noear
|
||||
* @author 夜の孤城
|
||||
* @author 暮城留风
|
||||
* @since 1.9
|
||||
* @since 2024-10-01
|
||||
* */
|
||||
public class Fastjson2ActionExecutor
|
||||
extends ActionExecuteHandlerDefault {
|
||||
private final Fastjson2StringSerializer serializer = new Fastjson2StringSerializer();
|
||||
* @since 3.6
|
||||
*/
|
||||
public class Fastjson2EntityConverter
|
||||
extends AbstractStringEntityConverter<Fastjson2StringSerializer> {
|
||||
public Fastjson2EntityConverter(Fastjson2StringSerializer serializer) {
|
||||
super(serializer);
|
||||
|
||||
public Fastjson2ActionExecutor() {
|
||||
serializer.getDeserializeConfig().config();
|
||||
serializer.getDeserializeConfig().config(JSONReader.Feature.ErrorOnEnumNotMatch);
|
||||
serializer.getDeserializeConfig().addFeatures(JSONReader.Feature.ErrorOnEnumNotMatch);
|
||||
serializer.getSerializeConfig().addFeatures(JSONWriter.Feature.BrowserCompatible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the serialization interface
|
||||
*/
|
||||
public Fastjson2StringSerializer getSerializer() {
|
||||
return serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the configuration
|
||||
*/
|
||||
public JSONReader.Context config() {
|
||||
return getSerializer().getDeserializeConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Match or not
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param mime Content type
|
||||
* Suffix or name mapping
|
||||
*/
|
||||
@Override
|
||||
public boolean matched(Context ctx, String mime) {
|
||||
return serializer.matched(ctx, mime);
|
||||
public String[] mappings() {
|
||||
return new String[]{SerializerNames.AT_JSON};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converting body
|
||||
* Change body
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param mWrap Method wrappers
|
||||
|
@ -67,7 +47,7 @@ public class Fastjson2ActionExecutor
|
|||
}
|
||||
|
||||
/**
|
||||
* 转换 value
|
||||
* Change value
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param p Parameter wrappers
|
||||
|
@ -96,7 +76,7 @@ public class Fastjson2ActionExecutor
|
|||
if (bodyObj instanceof JSONObject) {
|
||||
JSONObject tmp = (JSONObject) bodyObj;
|
||||
|
||||
if (!p.spec().isRequiredBody()) {
|
||||
if (p.spec().isRequiredBody() == false) {
|
||||
//
|
||||
//If there is no body requirement; Try to find by attribute
|
||||
//
|
||||
|
@ -149,4 +129,83 @@ public class Fastjson2ActionExecutor
|
|||
|
||||
return bodyObj;
|
||||
}
|
||||
|
||||
static class Fastjson2Decl<C, F> {
|
||||
private final boolean forSerialize;
|
||||
private C context;
|
||||
|
||||
public Fastjson2Decl(C context) {
|
||||
this.context = context;
|
||||
|
||||
if (context instanceof JSONWriter.Context) {
|
||||
forSerialize = true;
|
||||
} else {
|
||||
forSerialize = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get context
|
||||
*/
|
||||
public C getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset context
|
||||
*/
|
||||
public void setContext(C context) {
|
||||
Assert.notNull(context, "context can not be null");
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set features
|
||||
*/
|
||||
public void setFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
((JSONWriter.Context) context).setFeatures(JSONFactory.getDefaultWriterFeatures());
|
||||
} else {
|
||||
((JSONReader.Context) context).setFeatures(JSONFactory.getDefaultReaderFeatures());
|
||||
}
|
||||
|
||||
addFeatures(features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add features
|
||||
*/
|
||||
public void addFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
//序列化
|
||||
for (F f1 : features) {
|
||||
JSONWriter.Feature feature = (JSONWriter.Feature) f1;
|
||||
((JSONWriter.Context) context).config(feature, true);
|
||||
}
|
||||
} else {
|
||||
for (F f1 : features) {
|
||||
JSONReader.Feature feature = (JSONReader.Feature) f1;
|
||||
((JSONReader.Context) context).config(feature, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove features
|
||||
*/
|
||||
public void removeFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
//序列化
|
||||
for (F f1 : features) {
|
||||
JSONWriter.Feature feature = (JSONWriter.Feature) f1;
|
||||
((JSONWriter.Context) context).config(feature, false);
|
||||
}
|
||||
} else {
|
||||
for (F f1 : features) {
|
||||
JSONReader.Feature feature = (JSONReader.Feature) f1;
|
||||
((JSONReader.Context) context).config(feature, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
package com.alibaba.fastjson2.support.solon;
|
||||
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.noear.solon.core.handle.Render;
|
||||
import org.noear.solon.serialization.StringSerializerRender;
|
||||
import org.noear.solon.serialization.prop.JsonProps;
|
||||
import org.noear.solon.serialization.prop.JsonPropsUtil;
|
||||
|
||||
/**
|
||||
* Json RenderFactory
|
||||
*
|
||||
* @author noear
|
||||
* @author 暮城留风
|
||||
* @since 1.10
|
||||
* @since 2024-10-01
|
||||
*/
|
||||
public class Fastjson2RenderFactory
|
||||
extends Fastjson2RenderFactoryBase {
|
||||
public Fastjson2RenderFactory(JsonProps jsonProps) {
|
||||
serializer.cfgSerializeFeatures(false, true,
|
||||
JSONWriter.Feature.BrowserCompatible);
|
||||
applyProps(jsonProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suffix or name mapping
|
||||
*/
|
||||
@Override
|
||||
public String[] mappings() {
|
||||
return new String[]{"@json"};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Render
|
||||
*/
|
||||
@Override
|
||||
public Render create() {
|
||||
return new StringSerializerRender(false, serializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resetting features
|
||||
*/
|
||||
public void setFeatures(JSONWriter.Feature... features) {
|
||||
serializer.cfgSerializeFeatures(true, true, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding features
|
||||
*/
|
||||
public void addFeatures(JSONWriter.Feature... features) {
|
||||
serializer.cfgSerializeFeatures(false, true, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removing features
|
||||
*/
|
||||
public void removeFeatures(JSONWriter.Feature... features) {
|
||||
serializer.cfgSerializeFeatures(false, false, features);
|
||||
}
|
||||
|
||||
protected void applyProps(JsonProps jsonProps) {
|
||||
if (jsonProps != null && jsonProps.dateAsTicks) {
|
||||
jsonProps.dateAsTicks = false;
|
||||
this.getSerializer().getSerializeConfig()
|
||||
.setDateFormat("millis");
|
||||
}
|
||||
|
||||
if (JsonPropsUtil.apply(this, jsonProps)) {
|
||||
boolean writeNulls = jsonProps.nullAsWriteable ||
|
||||
jsonProps.nullNumberAsZero ||
|
||||
jsonProps.nullArrayAsEmpty ||
|
||||
jsonProps.nullBoolAsFalse ||
|
||||
jsonProps.nullStringAsEmpty;
|
||||
|
||||
if (jsonProps.nullStringAsEmpty) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteNullStringAsEmpty);
|
||||
}
|
||||
|
||||
if (jsonProps.nullBoolAsFalse) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteNullBooleanAsFalse);
|
||||
}
|
||||
|
||||
if (jsonProps.nullNumberAsZero) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteNullNumberAsZero);
|
||||
}
|
||||
|
||||
if (jsonProps.boolAsInt) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteBooleanAsNumber);
|
||||
}
|
||||
|
||||
if (jsonProps.longAsString) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteLongAsString);
|
||||
}
|
||||
|
||||
if (jsonProps.nullArrayAsEmpty) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteNullListAsEmpty);
|
||||
}
|
||||
|
||||
if (jsonProps.enumAsName) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteEnumsUsingName);
|
||||
}
|
||||
|
||||
if (writeNulls) {
|
||||
this.addFeatures(JSONWriter.Feature.WriteNulls);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.alibaba.fastjson2.support.solon;
|
||||
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
import org.noear.solon.core.convert.Converter;
|
||||
import org.noear.solon.serialization.JsonRenderFactory;
|
||||
|
||||
/**
|
||||
* Json RenderFactory Base
|
||||
*
|
||||
* @author noear
|
||||
* @author 暮城留风
|
||||
* @since 1.10
|
||||
* @since 2024-10-01
|
||||
*/
|
||||
public abstract class Fastjson2RenderFactoryBase
|
||||
implements JsonRenderFactory {
|
||||
protected Fastjson2StringSerializer serializer = new Fastjson2StringSerializer();
|
||||
|
||||
public Fastjson2RenderFactoryBase() {
|
||||
//The default time handling is a timestamp
|
||||
serializer.getSerializeConfig().setDateFormat("millis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the serializer
|
||||
*/
|
||||
public Fastjson2StringSerializer getSerializer() {
|
||||
return serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the configuration
|
||||
*/
|
||||
public ObjectWriterProvider config() {
|
||||
return serializer.getSerializeConfig().getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding the encoder
|
||||
*
|
||||
* @param clz type
|
||||
* @param encoder encoder
|
||||
*/
|
||||
public <T> void addEncoder(Class<T> clz, ObjectWriter encoder) {
|
||||
config().register(clz, encoder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add converter (simplified version of encoder)
|
||||
*
|
||||
* @param clz type
|
||||
* @param converter converter
|
||||
*/
|
||||
@Override
|
||||
public <T> void addConvertor(Class<T> clz, Converter<T, Object> converter) {
|
||||
addEncoder(clz, (out, obj, fieldName, fieldType, features) -> {
|
||||
Object val = converter.convert((T) obj);
|
||||
if (val == null) {
|
||||
out.writeNull();
|
||||
} else if (val instanceof String) {
|
||||
out.writeString((String) val);
|
||||
} else if (val instanceof Number) {
|
||||
if (val instanceof Long) {
|
||||
out.writeInt64(((Number) val).longValue());
|
||||
} else if (val instanceof Integer) {
|
||||
out.writeInt32(((Number) val).intValue());
|
||||
} else if (val instanceof Float) {
|
||||
out.writeDouble(((Number) val).floatValue());
|
||||
} else {
|
||||
out.writeDouble(((Number) val).doubleValue());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("The result type of the converter is not supported: " + val.getClass().getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.alibaba.fastjson2.support.solon;
|
||||
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.noear.solon.core.handle.Render;
|
||||
import org.noear.solon.serialization.StringSerializerRender;
|
||||
|
||||
/**
|
||||
* Json Typed RenderFactory (Typically used with RPC)
|
||||
*
|
||||
* @author noear
|
||||
* @author 暮城留风
|
||||
* @since 1.10
|
||||
* @since 2024-10-01
|
||||
*/
|
||||
public class Fastjson2RenderTypedFactory
|
||||
extends Fastjson2RenderFactoryBase {
|
||||
public Fastjson2RenderTypedFactory() {
|
||||
serializer.cfgSerializeFeatures(false, true,
|
||||
JSONWriter.Feature.BrowserCompatible,
|
||||
JSONWriter.Feature.WriteClassName,
|
||||
JSONWriter.Feature.ReferenceDetection,
|
||||
JSONWriter.Feature.WriteLongAsString
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suffix or name mapping
|
||||
*/
|
||||
@Override
|
||||
public String[] mappings() {
|
||||
return new String[]{"@type_json"};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Render
|
||||
*/
|
||||
@Override
|
||||
public Render create() {
|
||||
return new StringSerializerRender(true, serializer);
|
||||
}
|
||||
}
|
|
@ -5,90 +5,71 @@ import com.alibaba.fastjson2.JSONFactory;
|
|||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
import org.noear.solon.Utils;
|
||||
import org.noear.solon.core.convert.Converter;
|
||||
import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.handle.ModelAndView;
|
||||
import org.noear.solon.core.util.Assert;
|
||||
import org.noear.solon.core.util.MimeType;
|
||||
import org.noear.solon.lang.Nullable;
|
||||
import org.noear.solon.serialization.ContextSerializer;
|
||||
import org.noear.solon.serialization.EntityStringSerializer;
|
||||
import org.noear.solon.serialization.prop.JsonProps;
|
||||
import org.noear.solon.serialization.prop.JsonPropsUtil2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Fastjson2 string serialization
|
||||
* Fastjson2 字符串序列化
|
||||
*
|
||||
* @author noear
|
||||
* @author 暮城留风
|
||||
* @since 1.10
|
||||
* @since 2.8
|
||||
* @since 2024-10-01
|
||||
*/
|
||||
public class Fastjson2StringSerializer
|
||||
implements ContextSerializer<String> {
|
||||
implements EntityStringSerializer {
|
||||
private static final String label = "/json";
|
||||
private static final Fastjson2StringSerializer _default = new Fastjson2StringSerializer();
|
||||
|
||||
private JSONWriter.Context serializeConfig;
|
||||
private JSONReader.Context deserializeConfig;
|
||||
public static Fastjson2StringSerializer getDefault() {
|
||||
return _default;
|
||||
}
|
||||
|
||||
private Fastjson2Decl<JSONWriter.Context, JSONWriter.Feature> serializeConfig;
|
||||
private Fastjson2Decl<JSONReader.Context, JSONReader.Feature> deserializeConfig;
|
||||
|
||||
public Fastjson2StringSerializer(JsonProps jsonProps) {
|
||||
loadJsonProps(jsonProps);
|
||||
}
|
||||
|
||||
public Fastjson2StringSerializer() { }
|
||||
|
||||
/**
|
||||
* Get the serialization configuration
|
||||
* 获取序列化配置
|
||||
*/
|
||||
public JSONWriter.Context getSerializeConfig() {
|
||||
public Fastjson2Decl<JSONWriter.Context, JSONWriter.Feature> getSerializeConfig() {
|
||||
if (serializeConfig == null) {
|
||||
serializeConfig = new JSONWriter.Context(new ObjectWriterProvider());
|
||||
serializeConfig = new Fastjson2Decl<>(new JSONWriter.Context(new ObjectWriterProvider()));
|
||||
}
|
||||
|
||||
return serializeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the serialization feature
|
||||
*
|
||||
* @param isReset Reset or not
|
||||
* @param isAdd Add or not
|
||||
* @param features Feature
|
||||
* 获取反序列化配置
|
||||
*/
|
||||
public void cfgSerializeFeatures(boolean isReset, boolean isAdd, JSONWriter.Feature... features) {
|
||||
if (isReset) {
|
||||
getSerializeConfig().setFeatures(JSONFactory.getDefaultWriterFeatures());
|
||||
}
|
||||
|
||||
for (JSONWriter.Feature feature : features) {
|
||||
getSerializeConfig().config(feature, isAdd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the deserialized configuration
|
||||
*/
|
||||
public JSONReader.Context getDeserializeConfig() {
|
||||
public Fastjson2Decl<JSONReader.Context, JSONReader.Feature> getDeserializeConfig() {
|
||||
if (deserializeConfig == null) {
|
||||
deserializeConfig = new JSONReader.Context(new ObjectReaderProvider());
|
||||
deserializeConfig = new Fastjson2Decl<>(new JSONReader.Context(new ObjectReaderProvider()));
|
||||
}
|
||||
return deserializeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the deserialization feature
|
||||
*
|
||||
* @param isReset Reset or not
|
||||
* @param isAdd Add or not
|
||||
* @param features Feature
|
||||
*/
|
||||
public void cfgDeserializeFeatures(boolean isReset, boolean isAdd, JSONReader.Feature... features) {
|
||||
if (isReset) {
|
||||
getDeserializeConfig().setFeatures(JSONFactory.getDefaultReaderFeatures());
|
||||
}
|
||||
|
||||
for (JSONReader.Feature feature : features) {
|
||||
getDeserializeConfig().config(feature, isAdd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Content type
|
||||
* 内容类型
|
||||
*/
|
||||
@Override
|
||||
public String mimeType() {
|
||||
|
@ -96,7 +77,8 @@ public class Fastjson2StringSerializer
|
|||
}
|
||||
|
||||
/**
|
||||
* Data type
|
||||
* 数据类型
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Class<String> dataType() {
|
||||
|
@ -104,10 +86,10 @@ public class Fastjson2StringSerializer
|
|||
}
|
||||
|
||||
/**
|
||||
* Match or not
|
||||
* 是否匹配
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param mime content type
|
||||
* @param ctx 请求上下文
|
||||
* @param mime 内容类型
|
||||
*/
|
||||
@Override
|
||||
public boolean matched(Context ctx, String mime) {
|
||||
|
@ -119,7 +101,7 @@ public class Fastjson2StringSerializer
|
|||
}
|
||||
|
||||
/**
|
||||
* Serializer name
|
||||
* 序列化器名字
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
|
@ -127,39 +109,39 @@ public class Fastjson2StringSerializer
|
|||
}
|
||||
|
||||
/**
|
||||
* Serialize
|
||||
* 序列化
|
||||
*
|
||||
* @param obj object
|
||||
* @param obj 对象
|
||||
*/
|
||||
@Override
|
||||
public String serialize(Object obj) throws IOException {
|
||||
return JSON.toJSONString(obj, getSerializeConfig());
|
||||
return JSON.toJSONString(obj, getSerializeConfig().getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize
|
||||
* 反序列化
|
||||
*
|
||||
* @param data data
|
||||
* @param toType Target type
|
||||
* @param data 数据
|
||||
* @param toType 目标类型
|
||||
*/
|
||||
@Override
|
||||
public Object deserialize(String data, Type toType) throws IOException {
|
||||
if (toType == null) {
|
||||
return JSON.parse(data, getDeserializeConfig());
|
||||
return JSON.parse(data, getDeserializeConfig().getContext());
|
||||
} else {
|
||||
return JSON.parseObject(data, toType, getDeserializeConfig());
|
||||
return JSON.parseObject(data, toType, getDeserializeConfig().getContext());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the body
|
||||
* 序列化主体
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param data data
|
||||
* @param ctx 请求上下文
|
||||
* @param data 数据
|
||||
*/
|
||||
@Override
|
||||
public void serializeToBody(Context ctx, Object data) throws IOException {
|
||||
// If not set, use default // such as ndjson,sse or deliberately change mime (can be controlled externally)
|
||||
//如果没有设置过,用默认的 //如 ndjson,sse 或故意改变 mime(可由外部控制)
|
||||
if (ctx.contentTypeNew() == null) {
|
||||
ctx.contentType(this.mimeType());
|
||||
}
|
||||
|
@ -172,18 +154,178 @@ public class Fastjson2StringSerializer
|
|||
}
|
||||
|
||||
/**
|
||||
* Deserialize the body
|
||||
* 反序列化主体
|
||||
*
|
||||
* @param ctx Handling context
|
||||
* @param ctx 请求上下文
|
||||
*/
|
||||
@Override
|
||||
public Object deserializeFromBody(Context ctx, @Nullable Type bodyType) throws IOException {
|
||||
String data = ctx.bodyNew();
|
||||
|
||||
if (Utils.isNotEmpty(data)) {
|
||||
return JSON.parse(data, getDeserializeConfig());
|
||||
return JSON.parse(data, getDeserializeConfig().getContext());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加编码器
|
||||
*
|
||||
* @param clz 类型
|
||||
* @param encoder 编码器
|
||||
*/
|
||||
public <T> void addEncoder(Class<T> clz, ObjectWriter encoder) {
|
||||
getSerializeConfig().getContext().getProvider().register(clz, encoder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加转换器(编码器的简化版)
|
||||
*
|
||||
* @param clz 类型
|
||||
* @param converter 转换器
|
||||
*/
|
||||
@Override
|
||||
public <T> void addEncoder(Class<T> clz, Converter<T, Object> converter) {
|
||||
addEncoder(clz, (out, obj, fieldName, fieldType, features) -> {
|
||||
Object val = converter.convert((T) obj);
|
||||
if (val == null) {
|
||||
out.writeNull();
|
||||
} else if (val instanceof String) {
|
||||
out.writeString((String) val);
|
||||
} else if (val instanceof Number) {
|
||||
if (val instanceof Long) {
|
||||
out.writeInt64(((Number) val).longValue());
|
||||
} else if (val instanceof Integer) {
|
||||
out.writeInt32(((Number) val).intValue());
|
||||
} else if (val instanceof Float) {
|
||||
out.writeDouble(((Number) val).floatValue());
|
||||
} else {
|
||||
out.writeDouble(((Number) val).doubleValue());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("The result type of the converter is not supported: " + val.getClass().getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void loadJsonProps(JsonProps jsonProps) {
|
||||
if (jsonProps != null) {
|
||||
if (jsonProps.dateAsTicks) {
|
||||
jsonProps.dateAsTicks = false;
|
||||
getSerializeConfig().getContext().setDateFormat("millis");
|
||||
}
|
||||
|
||||
if (Utils.isNotEmpty(jsonProps.dateAsFormat)) {
|
||||
//这个方案,可以支持全局配置,且个性注解不会失效;//用编码器会让个性注解失效
|
||||
getSerializeConfig().getContext().setDateFormat(jsonProps.dateAsFormat);
|
||||
}
|
||||
|
||||
//JsonPropsUtil2.dateAsFormat(this, jsonProps);
|
||||
JsonPropsUtil2.dateAsTicks(this, jsonProps);
|
||||
JsonPropsUtil2.boolAsInt(this, jsonProps);
|
||||
|
||||
boolean writeNulls = jsonProps.nullAsWriteable ||
|
||||
jsonProps.nullNumberAsZero ||
|
||||
jsonProps.nullArrayAsEmpty ||
|
||||
jsonProps.nullBoolAsFalse ||
|
||||
jsonProps.nullStringAsEmpty;
|
||||
|
||||
if (jsonProps.nullStringAsEmpty) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteNullStringAsEmpty);
|
||||
}
|
||||
|
||||
if (jsonProps.nullBoolAsFalse) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteNullBooleanAsFalse);
|
||||
}
|
||||
|
||||
if (jsonProps.nullNumberAsZero) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteNullNumberAsZero);
|
||||
}
|
||||
|
||||
if (jsonProps.boolAsInt) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteBooleanAsNumber);
|
||||
}
|
||||
|
||||
if (jsonProps.longAsString) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteLongAsString);
|
||||
}
|
||||
|
||||
if (jsonProps.nullArrayAsEmpty) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteNullListAsEmpty);
|
||||
}
|
||||
|
||||
if (jsonProps.enumAsName) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteEnumsUsingName);
|
||||
}
|
||||
|
||||
if (writeNulls) {
|
||||
getSerializeConfig().addFeatures(JSONWriter.Feature.WriteNulls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Fastjson2Decl<C, F> {
|
||||
private final boolean forSerialize;
|
||||
private C context;
|
||||
|
||||
public Fastjson2Decl(C context) {
|
||||
this.context = context;
|
||||
|
||||
if (context instanceof JSONWriter.Context) {
|
||||
forSerialize = true;
|
||||
} else {
|
||||
forSerialize = false;
|
||||
}
|
||||
}
|
||||
|
||||
public C getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(C context) {
|
||||
Assert.notNull(context, "context can not be null");
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
((JSONWriter.Context) context).setFeatures(JSONFactory.getDefaultWriterFeatures());
|
||||
} else {
|
||||
((JSONReader.Context) context).setFeatures(JSONFactory.getDefaultReaderFeatures());
|
||||
}
|
||||
|
||||
addFeatures(features);
|
||||
}
|
||||
|
||||
public void addFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
//序列化
|
||||
for (F f1 : features) {
|
||||
JSONWriter.Feature feature = (JSONWriter.Feature) f1;
|
||||
((JSONWriter.Context) context).config(feature, true);
|
||||
}
|
||||
} else {
|
||||
for (F f1 : features) {
|
||||
JSONReader.Feature feature = (JSONReader.Feature) f1;
|
||||
((JSONReader.Context) context).config(feature, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFeatures(F... features) {
|
||||
if (forSerialize) {
|
||||
//序列化
|
||||
for (F f1 : features) {
|
||||
JSONWriter.Feature feature = (JSONWriter.Feature) f1;
|
||||
((JSONWriter.Context) context).config(feature, false);
|
||||
}
|
||||
} else {
|
||||
for (F f1 : features) {
|
||||
JSONReader.Feature feature = (JSONReader.Feature) f1;
|
||||
((JSONReader.Context) context).config(feature, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package com.alibaba.fastjson2.support.solon.integration;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2ActionExecutor;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderTypedFactory;
|
||||
import org.noear.solon.Solon;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2StringSerializer;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.noear.solon.core.Plugin;
|
||||
import org.noear.solon.serialization.SerializerNames;
|
||||
import org.noear.solon.serialization.prop.JsonProps;
|
||||
|
||||
/**
|
||||
|
@ -19,19 +18,14 @@ public class Fastjson2Plugin
|
|||
public void start(AppContext context) {
|
||||
JsonProps jsonProps = JsonProps.create(context);
|
||||
|
||||
//::renderFactory
|
||||
Fastjson2RenderFactory renderFactory = new Fastjson2RenderFactory(jsonProps); //绑定属性
|
||||
context.wrapAndPut(Fastjson2RenderFactory.class, renderFactory); //推入容器,用于扩展
|
||||
Solon.app().renderManager().register(renderFactory);
|
||||
//::serializer
|
||||
Fastjson2StringSerializer serializer = new Fastjson2StringSerializer(jsonProps);
|
||||
context.wrapAndPut(Fastjson2StringSerializer.class, serializer); //用于扩展
|
||||
context.app().serializers().register(SerializerNames.AT_JSON, serializer);
|
||||
|
||||
//::renderTypedFactory
|
||||
Fastjson2RenderTypedFactory renderTypedFactory = new Fastjson2RenderTypedFactory();
|
||||
context.wrapAndPut(Fastjson2RenderTypedFactory.class, renderTypedFactory); //推入容器,用于扩展
|
||||
Solon.app().renderManager().register(renderTypedFactory);
|
||||
|
||||
//::actionExecutor
|
||||
Fastjson2ActionExecutor actionExecutor = new Fastjson2ActionExecutor(); //支持 json 内容类型执行
|
||||
context.wrapAndPut(Fastjson2ActionExecutor.class, actionExecutor); //推入容器,用于扩展
|
||||
Solon.app().chainManager().addExecuteHandler(actionExecutor);
|
||||
//::entityConverter
|
||||
Fastjson2EntityConverter entityConverter = new Fastjson2EntityConverter(serializer);
|
||||
context.wrapAndPut(Fastjson2EntityConverter.class, entityConverter); //用于扩展
|
||||
context.app().chains().addEntityConverter(entityConverter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test0;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.snack.ONode;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -35,7 +35,7 @@ public class QuickConfigTest {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test1;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.snack.ONode;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -35,7 +35,7 @@ public class QuickConfigTest {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test1;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.snack.ONode;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest2 {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -35,7 +35,7 @@ public class QuickConfigTest2 {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test1_2;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.CustomDateDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.solon.annotation.Import;
|
||||
|
@ -17,7 +17,7 @@ import java.util.Date;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -27,7 +27,7 @@ public class QuickConfigTest {
|
|||
dateDo.setDate2(new Date(1673861993477L));
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(dateDo, ctx);
|
||||
entityConverter.write(dateDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test2;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.OrderDo;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -21,7 +21,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -36,7 +36,7 @@ public class QuickConfigTest {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
@ -54,7 +54,7 @@ public class QuickConfigTest {
|
|||
data.put("order", new OrderDo());
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(data, ctx);
|
||||
entityConverter.write(data, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test3;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.solon.annotation.Import;
|
||||
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -34,7 +34,7 @@ public class QuickConfigTest {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.fastjson2.support.solon.test.config.test4;
|
||||
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2RenderFactory;
|
||||
import com.alibaba.fastjson2.support.solon.Fastjson2EntityConverter;
|
||||
import com.alibaba.fastjson2.support.solon.test._model.UserDo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.solon.annotation.Import;
|
||||
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
@SolonTest
|
||||
public class QuickConfigTest {
|
||||
@Inject
|
||||
Fastjson2RenderFactory renderFactory;
|
||||
Fastjson2EntityConverter entityConverter;
|
||||
|
||||
@Test
|
||||
public void hello2() throws Throwable {
|
||||
|
@ -34,7 +34,7 @@ public class QuickConfigTest {
|
|||
userDo.setMap1(data);
|
||||
|
||||
ContextEmpty ctx = new ContextEmpty();
|
||||
renderFactory.create().render(userDo, ctx);
|
||||
entityConverter.write(userDo, ctx);
|
||||
String output = ctx.attr("output");
|
||||
|
||||
System.out.println(output);
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -35,7 +35,7 @@
|
|||
<jackson.version>2.20.0</jackson.version>
|
||||
<jetty.version>11.0.15</jetty.version>
|
||||
<jersey.version>2.44</jersey.version>
|
||||
<solon.version>3.4.3</solon.version>
|
||||
<solon.version>3.6.0</solon.version>
|
||||
<springframework5.version>5.3.31</springframework5.version>
|
||||
<springframework6.version>6.1.3</springframework6.version>
|
||||
<springsecurity5.version>5.8.8</springsecurity5.version>
|
||||
|
|
Loading…
Reference in New Issue