Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
change writeJSONString parameter sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 2, 2016
1 parent 5300025 commit b39c13a
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 43 deletions.
47 changes: 25 additions & 22 deletions src/main/java/com/alibaba/fastjson/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ public static String toJSONString(Object object, //
}
}

/**
* @deprecated
*/
public static String toJSONStringZ(Object object, SerializeConfig mapping, SerializerFeature... features) {
return toJSONString(object, mapping, emptyFilters, null, 0, features);
}
Expand Down Expand Up @@ -602,24 +605,24 @@ public static String toJSONString(Object object, boolean prettyFormat) {
* @deprecated use writeJSONString
*/
public static void writeJSONStringTo(Object object, Writer writer, SerializerFeature... features) {
writeJSONString(object, writer, features);
writeJSONString(writer, object, features);
}

/**
* write object as json to Writer
* @since 1.2.11
* @param object
* @param writer output writer
* @param object
* @param features serializer features
* @since 1.2.11
*/
public static void writeJSONString(Object object, Writer writer, SerializerFeature... features) {
writeJSONString(object, writer, JSON.DEFAULT_GENERATE_FEATURE, features);
public static void writeJSONString(Writer writer, Object object, SerializerFeature... features) {
writeJSONString(writer, object, JSON.DEFAULT_GENERATE_FEATURE, features);
}

/**
* @since 1.2.11
*/
public static void writeJSONString(Object object, Writer writer, int defaultFeatures, SerializerFeature... features) {
public static void writeJSONString(Writer writer, Object object, int defaultFeatures, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter(writer, defaultFeatures, features);

try {
Expand All @@ -632,52 +635,52 @@ public static void writeJSONString(Object object, Writer writer, int defaultFeat

/**
* write object as json to OutputStream
* @since 1.2.11
* @param object
* @param os output stream
* @param object
* @param features serializer features
* @since 1.2.11
* @throws IOException
*/
public static final int writeJSONString(Object object, //
OutputStream os, //
public static final int writeJSONString(OutputStream os, //
Object object, //
SerializerFeature... features) throws IOException {
return writeJSONString(object, os, DEFAULT_GENERATE_FEATURE, features);
return writeJSONString(os, object, DEFAULT_GENERATE_FEATURE, features);
}

/**
* @since 1.2.11
*/
public static final int writeJSONString(Object object, //
OutputStream os, //
public static final int writeJSONString(OutputStream os, //
Object object, //
int defaultFeatures, //
SerializerFeature... features) throws IOException {
return writeJSONString(object, //
os, //
IOUtils.UTF8, //
return writeJSONString(os, //
IOUtils.UTF8, //
object, //
SerializeConfig.globalInstance, //
null, //
null, //
defaultFeatures, //
features);
}

public static final int writeJSONString(Object object, //
OutputStream os, //
public static final int writeJSONString(OutputStream os, //
Charset charset, //
Object object, //
SerializerFeature... features) throws IOException {
return writeJSONString(object, //
os, //
return writeJSONString(os, //
charset, //
object, //
SerializeConfig.globalInstance, //
null, //
null, //
DEFAULT_GENERATE_FEATURE, //
features);
}

public static final int writeJSONString(Object object, //
OutputStream os, //
public static final int writeJSONString(OutputStream os, //
Charset charset, //
Object object, //
SerializeConfig config, //
SerializeFilter[] filters, //
String dateFormat, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ public void writeTo(Object obj, //
fastJsonConfig.setSerializerFeatures(serializerFeatures);
}

JSON.writeJSONString(obj, //
entityStream, //
JSON.writeJSONString(entityStream, //
fastJsonConfig.getCharset(), //
obj, //
fastJsonConfig.getSerializeConfig(), //
fastJsonConfig.getSerializeFilters(), //
fastJsonConfig.getDateFormat(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ protected void writeInternal(Object obj, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
HttpHeaders headers = outputMessage.getHeaders();
OutputStream out = outputMessage.getBody();
int len = JSON.writeJSONString(obj, //
out, //
int len = JSON.writeJSONString(out, //
fastJsonConfig.getCharset(), //
obj, //
fastJsonConfig.getSerializeConfig(), //
fastJsonConfig.getSerializeFilters(), //
fastJsonConfig.getDateFormat(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ protected void writeInternal(Object obj, //

HttpHeaders headers = outputMessage.getHeaders();
OutputStream out = outputMessage.getBody();
int len = JSON.writeJSONString(obj, //
out, //
int len = JSON.writeJSONString(out, //
fastJsonConfig.getCharset(), //
obj, //
fastJsonConfig.getSerializeConfig(), //
fastJsonConfig.getSerializeFilters(), //
fastJsonConfig.getDateFormat(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ protected void renderMergedOutputModel(Map<String, Object> model, //
Object value = filterModel(model);
OutputStream stream = this.updateContentLength ? createTemporaryOutputStream()
: response.getOutputStream();
JSON.writeJSONString(value, //
stream, //
JSON.writeJSONString(stream, //
fastJsonConfig.getCharset(), //
value, //
fastJsonConfig.getSerializeConfig(), //
fastJsonConfig.getSerializeFilters(), //
fastJsonConfig.getDateFormat(), //
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/alibaba/json/bvt/EnumFieldTest3.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void test_1_writer() throws Exception {
}

StringWriter writer = new StringWriter();
JSON.writeJSONString(array, writer);
JSON.writeJSONString(writer, array);
String text = writer.toString();

Model[] array2 = JSON.parseObject(text, Model[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void test_1_writer() throws Exception {
}

StringWriter writer = new StringWriter();
JSON.writeJSONString(array, writer);
JSON.writeJSONString(writer, array);
String text = writer.toString();

Model[] array2 = JSON.parseObject(text, Model[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void test_special() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer);
JSON.writeJSONString(writer, model);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand All @@ -34,7 +34,7 @@ public void test_special_browsecue() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer, SerializerFeature.BrowserSecure);
JSON.writeJSONString(writer, model, SerializerFeature.BrowserSecure);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand All @@ -49,7 +49,7 @@ public void test_special_browsecompatible() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer, SerializerFeature.BrowserCompatible);
JSON.writeJSONString(writer, model, SerializerFeature.BrowserCompatible);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void test_special() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer);
JSON.writeJSONString(writer, model);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand All @@ -34,7 +34,7 @@ public void test_special_browsecue() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer, SerializerFeature.UseSingleQuotes);
JSON.writeJSONString(writer, model, SerializerFeature.UseSingleQuotes);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand All @@ -49,7 +49,7 @@ public void test_special_browsecompatible() throws Exception {
model.name = buf.toString();

StringWriter writer = new StringWriter();
JSON.writeJSONString(model, writer, SerializerFeature.UseSingleQuotes);
JSON.writeJSONString(writer, model, SerializerFeature.UseSingleQuotes);

Model model2 = JSON.parseObject(writer.toString(), Model.class);
Assert.assertEquals(model.name, model2.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void test_array_writer() throws Exception {
long[] values = new long[] {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE};

StringWriter writer = new StringWriter();
JSON.writeJSONString(values, writer, SerializerFeature.BrowserCompatible);
JSON.writeJSONString(writer, values, SerializerFeature.BrowserCompatible);
String text = writer.toString();
long[] values_2 = JSON.parseObject(text, long[].class);
Assert.assertEquals(values_2.length, values.length);
Expand All @@ -45,7 +45,7 @@ public void test_array_writer_2() throws Exception {
}

StringWriter writer = new StringWriter();
JSON.writeJSONString(values, writer, SerializerFeature.BrowserCompatible);
JSON.writeJSONString(writer, values, SerializerFeature.BrowserCompatible);
String text = writer.toString();
long[] values_2 = JSON.parseObject(text, long[].class);
Assert.assertEquals(values_2.length, values.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void test_writeJSONStringTo() throws Exception {
model.name = "中文名称";

ByteArrayOutputStream os = new ByteArrayOutputStream();
JSON.writeJSONString(model, os);
JSON.writeJSONString(os, model);
os.close();

byte[] bytes = os.toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public byte[] encodeToBytes(Object object) throws Exception {

@Override
public void encode(OutputStream out, Object object) throws Exception {
JSON.writeJSONString(object, out, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.BeanToArray);
JSON.writeJSONString(out, object, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.BeanToArray);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public byte[] encodeToBytes(Object object) throws Exception {

@Override
public void encode(OutputStream out, Object object) throws Exception {
JSON.writeJSONString(object, out, SerializerFeature.DisableCircularReferenceDetect);
JSON.writeJSONString(out, object, SerializerFeature.DisableCircularReferenceDetect);
}

}

0 comments on commit b39c13a

Please sign in to comment.