use of com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class MalformedJsonTest method dictInsteadOfScalar.
@Test
public void dictInsteadOfScalar() throws IOException, JSONException {
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(SimpleParseUUT.STRING_FIELD_NAME).object().key("garbage").value("123").endObject().key(SimpleParseUUT.INT_FIELD_NAME).value(intValue).key(SimpleParseUUT.INTEGER_FIELD_NAME).value(integerValue).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
SimpleParseUUT uut = SimpleParseUUT__JsonHelper.parseFromJson(jp);
assertSame(intValue, uut.intField);
assertSame(integerValue, uut.integerField.intValue());
assertNull(uut.stringField);
}
use of com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class SerializeTest method serializeOrderTest.
@Test
public void serializeOrderTest() throws IOException {
final int intValue = 25;
final int integerValue = 37;
final float floatValue = 1f;
final float floatObjectValue = 5f;
final String stringValue = "hello world\r\n\'\"";
final List<Integer> integerList = Lists.newArrayList(1, 2, 3, 4);
final ArrayList<Integer> integerArrayList = Lists.newArrayList(1, 2, 3, 4);
final Queue<Integer> integerQueue = Queues.newArrayDeque(Arrays.asList(1, 2, 3, 4));
final Set<Integer> integerSet = Sets.newHashSet(1, 2, 3, 4);
final int subIntValue = 30;
final SimpleParseUUT.SubenumUUT subEnum = SimpleParseUUT.SubenumUUT.A;
final List<SimpleParseUUT.SubenumUUT> subEnumList = Lists.newArrayList(SimpleParseUUT.SubenumUUT.A, SimpleParseUUT.SubenumUUT.B);
SimpleParseUUT source = new SimpleParseUUT();
source.intField = intValue;
source.integerField = integerValue;
source.floatField = floatValue;
source.FloatField = floatObjectValue;
source.stringField = stringValue;
source.integerListField = integerList;
source.integerArrayListField = integerArrayList;
source.integerQueueField = integerQueue;
source.integerSetField = integerSet;
source.subobjectField = new SimpleParseUUT.SubobjectParseUUT();
source.subobjectField.intField = subIntValue;
source.subenumField = subEnum;
source.subenumFieldList = subEnumList;
StringWriter stringWriter = new StringWriter();
JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
SimpleParseUUT__JsonHelper.serializeToJson(jsonGenerator, source, true);
jsonGenerator.close();
String inputString = stringWriter.toString();
// Test that fields appear in the order specified in the class
for (int i = 0; i < FIELD_DECLARATION_ORDER.length - 1; i++) {
assertTrue(inputString.indexOf("\"" + FIELD_DECLARATION_ORDER[i] + "\"") < inputString.indexOf("\"" + FIELD_DECLARATION_ORDER[i + 1] + "\""));
}
}
use of com.fasterxml.jackson.core.JsonFactory in project hadoop by apache.
the class QueueManager method dumpConfiguration.
/***
* Dumps the configuration of hierarchy of queues with
* the xml file path given. It is to be used directly ONLY FOR TESTING.
* @param out the writer object to which dump is written to.
* @param configFile the filename of xml file
* @throws IOException
*/
static void dumpConfiguration(Writer out, String configFile, Configuration conf) throws IOException {
if (conf != null && conf.get(DeprecatedQueueConfigurationParser.MAPRED_QUEUE_NAMES_KEY) != null) {
return;
}
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
QueueConfigurationParser parser;
boolean aclsEnabled = false;
if (conf != null) {
aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
}
if (configFile != null && !"".equals(configFile)) {
parser = new QueueConfigurationParser(configFile, aclsEnabled);
} else {
parser = getQueueConfigurationParser(null, false, aclsEnabled);
}
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("queues");
dumpGenerator.writeStartArray();
dumpConfiguration(dumpGenerator, parser.getRoot().getChildren());
dumpGenerator.writeEndArray();
dumpGenerator.writeEndObject();
dumpGenerator.flush();
}
use of com.fasterxml.jackson.core.JsonFactory in project hadoop by apache.
the class JMXJsonServlet method init.
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
// Retrieve the MBean server
mBeanServer = ManagementFactory.getPlatformMBeanServer();
jsonFactory = new JsonFactory();
}
use of com.fasterxml.jackson.core.JsonFactory in project pysonar2 by yinwang0.
the class JSONDump method graph.
/*
* Precondition: srcpath and inclpaths are absolute paths
*/
private static void graph(String srcpath, String[] inclpaths, OutputStream symOut, OutputStream refOut, OutputStream docOut) throws Exception {
// Compute parent dirs, sort by length so potential prefixes show up first
List<String> parentDirs = Lists.newArrayList(inclpaths);
parentDirs.add(dirname(srcpath));
Collections.sort(parentDirs, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
int diff = s1.length() - s2.length();
if (0 == diff) {
return s1.compareTo(s2);
}
return diff;
}
});
Analyzer idx = newAnalyzer(srcpath, inclpaths);
idx.multilineFunType = true;
JsonFactory jsonFactory = new JsonFactory();
JsonGenerator symJson = jsonFactory.createGenerator(symOut);
JsonGenerator refJson = jsonFactory.createGenerator(refOut);
JsonGenerator docJson = jsonFactory.createGenerator(docOut);
JsonGenerator[] allJson = { symJson, refJson, docJson };
for (JsonGenerator json : allJson) {
json.writeStartArray();
}
for (Binding b : idx.getAllBindings()) {
String path = b.qname.replace('.', '/').replace("%20", ".");
if (b.getFile() != null) {
if (b.getFile().startsWith(srcpath)) {
writeSymJson(b, symJson);
writeDocJson(b, idx, docJson);
}
}
for (Node ref : b.refs) {
if (ref.file != null) {
if (ref.file.startsWith(srcpath)) {
writeRefJson(ref, b, refJson);
}
}
}
}
for (JsonGenerator json : allJson) {
json.writeEndArray();
json.close();
}
}
Aggregations