com.alibaba.fastjson2.support.redission.JSONBCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson2-extension Show documentation
Show all versions of fastjson2-extension Show documentation
Fastjson is a JSON processor (JSON parser + JSON generator) written in Java
package com.alibaba.fastjson2.support.redission;
import com.alibaba.fastjson2.*;
import com.alibaba.fastjson2.writer.ObjectWriter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import java.io.IOException;
import java.lang.reflect.Type;
public class JSONBCodec
extends BaseCodec {
final JSONBEncoder encoder;
final JSONBDecoder decoder;
public JSONBCodec(Type valueType) {
this(
JSONFactory.createWriteContext(JSONWriter.Feature.FieldBased),
JSONFactory.createReadContext(JSONReader.Feature.FieldBased),
valueType);
}
/**
*
* @param autoTypes Support for automatically typed class name prefixes
* @since 2.0.50
*/
public JSONBCodec(String... autoTypes) {
this(
JSONFactory.createWriteContext(JSONWriter.Feature.FieldBased, JSONWriter.Feature.WriteClassName),
JSONFactory.createReadContext(
JSONReader.autoTypeFilter(autoTypes),
JSONReader.Feature.FieldBased),
null);
}
public JSONBCodec(JSONWriter.Context writerContext, JSONReader.Context readerContext) {
this(writerContext, readerContext, null);
}
public JSONBCodec(JSONWriter.Context writerContext, JSONReader.Context readerContext, Type valueType) {
this(new JSONBEncoder(writerContext), new JSONBDecoder(readerContext, valueType));
}
protected JSONBCodec(JSONBEncoder encoder, JSONBDecoder decoder) {
this.encoder = encoder;
this.decoder = decoder;
}
@Override
public Decoder