com.alibaba.fastjson2.support.redission.JSONCodec 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
The newest version!
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;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class JSONCodec
extends BaseCodec {
final JSONEncoder encoder;
final JSONDecoder decoder;
public JSONCodec(Type type) {
this(JSONFactory.createWriteContext(), JSONFactory.createReadContext(), type, StandardCharsets.UTF_8);
}
public JSONCodec(Type type, Charset charset) {
this(JSONFactory.createWriteContext(), JSONFactory.createReadContext(), type, charset);
}
public JSONCodec(JSONWriter.Context writerContext, JSONReader.Context readerContext) {
this(writerContext, readerContext, null, StandardCharsets.UTF_8);
}
public JSONCodec(JSONWriter.Context writerContext, JSONReader.Context readerContext, Charset charset) {
this(writerContext, readerContext, null, charset);
}
public JSONCodec(JSONWriter.Context writerContext, JSONReader.Context readerContext, Type valueType, Charset charset) {
this(new JSONEncoder(writerContext, charset), new JSONDecoder(valueType, charset, readerContext));
}
JSONCodec(JSONEncoder encoder, JSONDecoder decoder) {
this.encoder = encoder;
this.decoder = decoder;
}
@Override
public Decoder