Skip to content

Commit

Permalink
rename all attribute fastJsonConfig to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorZeng committed May 25, 2022
1 parent 057173e commit 15ce51d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public class Retrofit2ConverterFactory
extends Converter.Factory {
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");

private FastJsonConfig fastJsonConfig;
private FastJsonConfig config;

public Retrofit2ConverterFactory() {
this.fastJsonConfig = new FastJsonConfig();
this.config = new FastJsonConfig();
}

public Retrofit2ConverterFactory(FastJsonConfig fastJsonConfig) {
this.fastJsonConfig = fastJsonConfig;
this.config = fastJsonConfig;
}

public static Retrofit2ConverterFactory create() {
Expand Down Expand Up @@ -61,11 +61,11 @@ public Converter<Object, RequestBody> requestBodyConverter(Type type, //
}

public FastJsonConfig getFastJsonConfig() {
return fastJsonConfig;
return config;
}

public Retrofit2ConverterFactory setFastJsonConfig(FastJsonConfig fastJsonConfig) {
this.fastJsonConfig = fastJsonConfig;
this.config = fastJsonConfig;
return this;
}

Expand All @@ -80,8 +80,7 @@ final class ResponseBodyConverter<T>
@Override
public T convert(ResponseBody value) throws IOException {
try {
return JSON.parseObject(value.bytes(), type,
fastJsonConfig.getDateFormat(), fastJsonConfig.getReaderFeatures());
return JSON.parseObject(value.bytes(), type, config.getDateFormat(), config.getReaderFeatures());
} catch (Exception e) {
throw new IOException("JSON parse error: " + e.getMessage(), e);
} finally {
Expand All @@ -98,8 +97,7 @@ final class RequestBodyConverter<T>
@Override
public RequestBody convert(T value) throws IOException {
try {
byte[] content = JSON.toJSONBytes(value, fastJsonConfig.getDateFormat(),
fastJsonConfig.getWriterFilters(), fastJsonConfig.getWriterFeatures());
byte[] content = JSON.toJSONBytes(value, config.getDateFormat(), config.getWriterFilters(), config.getWriterFeatures());
return RequestBody.create(MEDIA_TYPE, content);
} catch (Exception e) {
throw new IOException("Could not write JSON: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FastJsonHttpMessageConverter
/**
* with fastJson config
*/
private FastJsonConfig fastJsonConfig = new FastJsonConfig();
private FastJsonConfig config = new FastJsonConfig();

/**
* Can serialize/deserialize all types.
Expand All @@ -47,14 +47,14 @@ public FastJsonHttpMessageConverter() {
* @return the fastJsonConfig.
*/
public FastJsonConfig getFastJsonConfig() {
return fastJsonConfig;
return config;
}

/**
* @param fastJsonConfig the fastJsonConfig to set.
*/
public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
this.fastJsonConfig = fastJsonConfig;
this.config = fastJsonConfig;
}

@Override
Expand Down Expand Up @@ -105,8 +105,7 @@ private Object readType(Type type, HttpInputMessage inputMessage) {
}
byte[] bytes = baos.toByteArray();

return JSON.parseObject(bytes, type,
fastJsonConfig.getDateFormat(), fastJsonConfig.getReaderFeatures());
return JSON.parseObject(bytes, type, config.getDateFormat(), config.getReaderFeatures());
} catch (JSONException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex, inputMessage);
} catch (IOException ex) {
Expand All @@ -119,10 +118,9 @@ protected void writeInternal(Object object, HttpOutputMessage outputMessage) thr
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
HttpHeaders headers = outputMessage.getHeaders();

int len = JSON.writeTo(baos, object, fastJsonConfig.getDateFormat(),
fastJsonConfig.getWriterFilters(), fastJsonConfig.getWriterFeatures());
int len = JSON.writeTo(baos, object, config.getDateFormat(), config.getWriterFilters(), config.getWriterFeatures());

if (headers.getContentLength() < 0 && fastJsonConfig.isWriteContentLength()) {
if (headers.getContentLength() < 0 && config.isWriteContentLength()) {
headers.setContentLength(len);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -43,7 +42,7 @@ public class FastJsonJsonView
/**
* with fastJson config
*/
private FastJsonConfig fastJsonConfig = new FastJsonConfig();
private FastJsonConfig config = new FastJsonConfig();

/**
* Set default param.
Expand All @@ -57,14 +56,14 @@ public FastJsonJsonView() {
* @return the fastJsonConfig.
*/
public FastJsonConfig getFastJsonConfig() {
return fastJsonConfig;
return config;
}

/**
* @param fastJsonConfig the fastJsonConfig to set.
*/
public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
this.fastJsonConfig = fastJsonConfig;
this.config = fastJsonConfig;
}

/**
Expand Down Expand Up @@ -100,9 +99,9 @@ protected void renderMergedOutputModel(Map<String, Object> model, //

ByteArrayOutputStream outnew = new ByteArrayOutputStream();

int len = JSON.writeTo(outnew, value, fastJsonConfig.getDateFormat(), fastJsonConfig.getWriterFilters(), fastJsonConfig.getWriterFeatures());
int len = JSON.writeTo(outnew, value, config.getDateFormat(), config.getWriterFilters(), config.getWriterFeatures());

if (fastJsonConfig.isWriteContentLength()) {
if (config.isWriteContentLength()) {
// Write content length (determined via byte array).
response.setContentLength(len);
}
Expand All @@ -118,7 +117,7 @@ protected void renderMergedOutputModel(Map<String, Object> model, //
protected void prepareResponse(HttpServletRequest request, //
HttpServletResponse response) {
setResponseContentType(request, response);
response.setCharacterEncoding(fastJsonConfig.getCharset().name());
response.setCharacterEncoding(config.getCharset().name());
if (this.disableCaching) {
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache, no-store, max-age=0");
Expand All @@ -144,7 +143,7 @@ public void setDisableCaching(boolean disableCaching) {
* The default setting is {@code false}.
*/
public void setUpdateContentLength(boolean updateContentLength) {
this.fastJsonConfig.setWriteContentLength(updateContentLength);
this.config.setWriteContentLength(updateContentLength);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

public class FastjsonSockJsMessageCodec
extends AbstractSockJsMessageCodec {
private FastJsonConfig fastJsonConfig = new FastJsonConfig();
private FastJsonConfig config = new FastJsonConfig();

public FastJsonConfig getFastJsonConfig() {
return fastJsonConfig;
return config;
}

public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
this.fastJsonConfig = fastJsonConfig;
this.config = fastJsonConfig;
}

@Override
Expand All @@ -36,7 +36,7 @@ protected char[] applyJsonQuoting(String content) {

@Override
public String encode(String... messages) {
JSONWriter jsonWriter = JSONWriter.of(fastJsonConfig.getWriterFeatures());
JSONWriter jsonWriter = JSONWriter.of(config.getWriterFeatures());
if (jsonWriter.isUTF8()) {
jsonWriter.writeRaw(new byte[]{'a'});
} else {
Expand Down

0 comments on commit 15ce51d

Please sign in to comment.