mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Get rid of jackson (mostly)
Reviewed By: astreet Differential Revision: D3041362 fb-gh-sync-id: a7027a08a63730b98dc766b86921820fa3624953 shipit-source-id: a7027a08a63730b98dc766b86921820fa3624953
This commit is contained in:
committed by
Facebook Github Bot 8
parent
14555063bb
commit
d329570ac8
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper for generating JSON for lists and maps.
|
||||
*/
|
||||
class JsonWriterHelper {
|
||||
public static void value(JsonWriter writer, Object value) throws IOException {
|
||||
if (value instanceof Map) {
|
||||
mapValue(writer, (Map) value);
|
||||
} else if (value instanceof List) {
|
||||
listValue(writer, (List) value);
|
||||
} else {
|
||||
objectValue(writer, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void mapValue(JsonWriter writer, Map<?, ?> map) throws IOException {
|
||||
writer.beginObject();
|
||||
for (Map.Entry entry : map.entrySet()) {
|
||||
writer.name(entry.getKey().toString());
|
||||
value(writer, entry.getValue());
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
private static void listValue(JsonWriter writer, List<?> list) throws IOException {
|
||||
writer.beginArray();
|
||||
for (Object item : list) {
|
||||
objectValue(writer, item);
|
||||
}
|
||||
writer.endArray();
|
||||
}
|
||||
|
||||
private static void objectValue(JsonWriter writer, Object value) throws IOException {
|
||||
if (value == null) {
|
||||
writer.nullValue();
|
||||
} else if (value instanceof String) {
|
||||
writer.value((String) value);
|
||||
} else if (value instanceof Number) {
|
||||
writer.value((Number) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
writer.value((Boolean) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown value: " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user