本文整理了Java中com.amazonaws.util.json.JsonUtils.getJsonWriter()
方法的一些代码示例,展示了JsonUtils.getJsonWriter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils.getJsonWriter()
方法的具体详情如下:
包路径:com.amazonaws.util.json.JsonUtils
类名称:JsonUtils
方法名:getJsonWriter
[英]Gets a JSON writer. If no JSON engine is available, an AmazonClientException will be thrown.
[中]获取一个JSON编写器。如果没有可用的JSON引擎,将抛出AmazonClientException。
代码示例来源:origin: aws-amplify/aws-sdk-android
/**
* Constructs a new instance of JSONPolicyWriter.
*/
public JsonPolicyWriter() {
writer = new StringWriter();
jsonWriter = JsonUtils.getJsonWriter(writer);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
/**
* Encode a string to string map as a JSON string.
*
* @param map map to be encoded
* @return a non null JSON string
*/
public static String mapToString(Map<String, String> map) {
if (map == null || map.isEmpty()) {
return "{}";
}
try {
StringWriter out = new StringWriter();
AwsJsonWriter writer = getJsonWriter(out);
writer.beginObject();
for (Map.Entry<String, String> entry : map.entrySet()) {
writer.name(entry.getKey()).value(entry.getValue());
}
writer.endObject();
writer.close();
return out.toString();
} catch (IOException e) {
throw new AmazonClientException("Unable to serialize to JSON String.", e);
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
try {
StringWriter stringWriter = new StringWriter();
AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(stringWriter);
if (createAppRequest.getCreateApplicationRequest() != null) {
CreateApplicationRequest createApplicationRequest = createAppRequest
代码示例来源:origin: aws-amplify/aws-sdk-android
String toJson() throws IOException {
final StringWriter out = new StringWriter();
JsonUtils.getJsonWriter(out)
.beginObject()
.name("s3")
.beginObject()
.name("bucket").value(bucket)
.name("key").value(key)
.name("region").value(regionId)
.endObject()
.endObject()
.close();
return out.toString();
}
代码示例来源:origin: aws-amplify/aws-sdk-android
try {
StringWriter stringWriter = new StringWriter();
AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(stringWriter);
jsonWriter.beginObject();
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public String serialize() {
StringWriter out = new StringWriter();
AwsJsonWriter writer = JsonUtils.getJsonWriter(out);
try {
writer.beginObject()
.name("pauseType").value(TYPE)
.name("bucketName").value(bucketName)
.name("key").value(key)
.name("file").value(file)
.name("multipartUploadId").value(multipartUploadId)
.name("partSize").value(partSize)
.name("mutlipartUploadThreshold").value(mutlipartUploadThreshold)
.endObject().close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
return out.toString();
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testDate() throws IOException {
Date d = new Date(1423875641895L);
String target = "1423875641.895";
JsonUtils.setJsonEngine(JsonEngine.Gson);
StringWriter out = new StringWriter();
// This is wrapped in an array so that Gson doesn't complain about
// invalid JSON encoding
JsonUtils.getJsonWriter(out)
.beginArray().value(d).endArray()
.close();
assertEquals("[" + target + "]", out.toString());
out.getBuffer().setLength(0); // clear string writer
JsonUtils.setJsonEngine(JsonEngine.Jackson);
JsonUtils.getJsonWriter(out)
.beginArray().value(d).endArray()
.close();
assertEquals("[" + target + "]", out.toString());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testByteBuffer() throws IOException {
ByteBuffer bb = generateByteBuffer(16);
// Note: the target string is back filled with the output of the above
// byte buffer
String target = "AAECAwQFBgcICQoLDA0ODw==";
JsonUtils.setJsonEngine(JsonEngine.Gson);
StringWriter out = new StringWriter();
JsonUtils.getJsonWriter(out)
.beginArray().value(bb).endArray()
.close();
assertEquals("[\"" + target + "\"]", out.toString());
out.getBuffer().setLength(0);
JsonUtils.setJsonEngine(JsonEngine.Jackson);
JsonUtils.getJsonWriter(out)
.beginArray().value(bb).endArray()
.close();
assertEquals("[\"" + target + "\"]", out.toString());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testBigDecimalJsonUnmarshaller() throws Exception {
BigDecimal bd = new BigDecimal("1.5");
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("bd");
jw.value(bd.toPlainString());
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.BigDecimalJsonUnmarshaller bdUnmarshaller = SimpleTypeJsonUnmarshallers.BigDecimalJsonUnmarshaller
.getInstance();
BigDecimal unmarshalledBD = bdUnmarshaller.unmarshall(context);
assertEquals(unmarshalledBD.toPlainString(), bd.toPlainString());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testBigIntegerJsonUnmarshaller() throws Exception {
BigInteger bi = new BigInteger("13459712934871293847891231293874");
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("bi");
jw.value(bi.toString());
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.BigIntegerJsonUnmarshaller biUnmarshaller = SimpleTypeJsonUnmarshallers.BigIntegerJsonUnmarshaller
.getInstance();
BigInteger unmarshalledBI = biUnmarshaller.unmarshall(context);
assertEquals(unmarshalledBI.toString(), bi.toString());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testByteBufferJsonUnmarshaller() throws Exception {
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("bb");
jw.value(Base64.encodeAsString("byte".getBytes(StringUtils.UTF8)));
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.ByteBufferJsonUnmarshaller bbUnmarshaller = SimpleTypeJsonUnmarshallers.ByteBufferJsonUnmarshaller
.getInstance();
ByteBuffer unmarshalledBb = bbUnmarshaller.unmarshall(context);
ByteBuffer expected = ByteBuffer.wrap("byte".getBytes(StringUtils.UTF8));
assertTrue(unmarshalledBb.equals(expected));
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testDateJsonUnmarshaller() throws Exception {
Date date = new Date();
date.setTime(1000);
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("date");
jw.value(date);
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller dateUnmarshaller = SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller
.getInstance();
Date unmarshalledDate = dateUnmarshaller.unmarshall(context);
assertEquals(unmarshalledDate.getTime(), date.getTime());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testFloatJsonUnmarshaller() throws Exception {
Float f = new Float(5.5);
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("f");
jw.value(f);
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.FloatJsonUnmarshaller fUnmarshaller = SimpleTypeJsonUnmarshallers.FloatJsonUnmarshaller
.getInstance();
Float unmarshalledF = fUnmarshaller.unmarshall(context);
assertEquals(unmarshalledF.floatValue(), 5.5, .001);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testDoubleJsonUnmarshaller() throws Exception {
Double dub = new Double(5.5);
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("dub");
jw.value(dub);
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.DoubleJsonUnmarshaller dubUnmarshaller = SimpleTypeJsonUnmarshallers.DoubleJsonUnmarshaller
.getInstance();
Double unmarshalledDub = dubUnmarshaller.unmarshall(context);
assertEquals(unmarshalledDub.doubleValue(), 5.5, .001);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testLongJsonUnmarshaller() throws Exception {
Long l = new Long(5L);
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("l");
jw.value(l);
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.LongJsonUnmarshaller lUnmarshaller = SimpleTypeJsonUnmarshallers.LongJsonUnmarshaller
.getInstance();
Long unmarshalledL = lUnmarshaller.unmarshall(context);
assertEquals(unmarshalledL.longValue(), 5L);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testIntegerJsonUnmarshaller() throws Exception {
Integer i = new Integer(5);
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("i");
jw.value(i);
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.IntegerJsonUnmarshaller iUnmarshaller = SimpleTypeJsonUnmarshallers.IntegerJsonUnmarshaller
.getInstance();
Integer unmarshalledI = iUnmarshaller.unmarshall(context);
assertEquals(unmarshalledI.intValue(), 5);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testByteJsonUnmarshaller() throws Exception {
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("b");
jw.value(Byte.valueOf("127"));
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.ByteJsonUnmarshaller bUnmarshaller = SimpleTypeJsonUnmarshallers.ByteJsonUnmarshaller
.getInstance();
Byte unmarshalledB = bUnmarshaller.unmarshall(context);
Byte expected = Byte.valueOf("127");
assertTrue(unmarshalledB.equals(expected));
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testStringJsonUnmarshaller() throws Exception {
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("s");
jw.value("String");
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller sUnmarshaller = SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller
.getInstance();
assertEquals(sUnmarshaller.unmarshall(context), "String");
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testBooleanJsonUnmarshaller() throws Exception {
StringWriter sw = new StringWriter();
AwsJsonWriter jw = JsonUtils.getJsonWriter(sw);
jw.beginObject();
jw.name("boolean");
jw.value("true");
jw.endObject();
String json = sw.toString();
StringReader sr = new StringReader(json);
AwsJsonReader jr = JsonUtils.getJsonReader(sr);
JsonUnmarshallerContext context = new JsonUnmarshallerContext(jr);
context.getReader().beginObject();
context.getReader().nextName();
SimpleTypeJsonUnmarshallers.BooleanJsonUnmarshaller bUnmarshaller = SimpleTypeJsonUnmarshallers.BooleanJsonUnmarshaller
.getInstance();
Boolean unmarshalledB = bUnmarshaller.unmarshall(context);
assertTrue(unmarshalledB);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonWriter() throws IOException {
StringWriter out = new StringWriter();
AwsJsonWriter writer = JsonUtils.getJsonWriter(out);
writer.beginObject()
.name("string").value("string")
.name("long").value(123)
.name("double").value(123.45)
.name("null").value()
.name("true").value(true)
.name("false").value(false)
.name("encoding").value("Chloë")
.name("array").beginArray()
.value("string").value(123).value(123.45).value().value(true).value(false)
.endArray()
.name("object").beginObject().endObject()
.endObject().close();
String json = out.toString();
assertEquals("same json", JSON_STRING, json);
}
内容来源于网络,如有侵权,请联系作者删除!