use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class NobodiesTest method serializeIsNoOp.
@Test
public void serializeIsNoOp() throws IOException {
StringWriter stringWriter = new StringWriter();
JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
NoBodyUUT obj = new NoBodyUUT();
obj.mValue = "some-value";
NoBodyUUT__JsonHelper.serializeToJson(jsonGenerator, obj, true);
jsonGenerator.close();
String serialized = stringWriter.toString();
assertEquals("{}", serialized);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class SerializeTest method serializeWithGetterTest.
@Test
public void serializeWithGetterTest() throws IOException {
GetterUUT source = new GetterUUT();
source.intField = 5;
StringWriter stringWriter = new StringWriter();
JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter);
GetterUUT__JsonHelper.serializeToJson(jsonGenerator, source, true);
jsonGenerator.close();
String inputString = stringWriter.toString();
GetterUUT parsed = GetterUUT__JsonHelper.parseFromJson(inputString);
assertEquals(10, parsed.intField);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class SerializeTest method serializeInterfaceWithWrapperTest.
@Test
public void serializeInterfaceWithWrapperTest() throws IOException {
StringWriter stringWriter;
JsonGenerator jsonGenerator;
InterfaceImplementationUUT obj = new InterfaceImplementationUUT();
obj.mStringField = "testValue";
InterfaceImplementation2UUT obj2 = new InterfaceImplementation2UUT();
obj2.mIntegerField = 5;
WrapperInterfaceUUT wrapper = new WrapperInterfaceUUT();
stringWriter = new StringWriter();
jsonGenerator = new JsonFactory().createGenerator(stringWriter);
wrapper.mInterfaceParentWithWrapper = obj;
WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
jsonGenerator.close();
String serialized = stringWriter.toString();
WrapperInterfaceUUT parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
assertNotNull(parsed);
assertTrue(parsed.mInterfaceParentWithWrapper instanceof InterfaceImplementationUUT);
InterfaceImplementationUUT parsedObj = (InterfaceImplementationUUT) parsed.mInterfaceParentWithWrapper;
assertEquals(obj.mStringField, parsedObj.mStringField);
stringWriter = new StringWriter();
jsonGenerator = new JsonFactory().createGenerator(stringWriter);
wrapper.mInterfaceParentWithWrapper = obj2;
WrapperInterfaceUUT__JsonHelper.serializeToJson(jsonGenerator, wrapper, true);
jsonGenerator.close();
serialized = stringWriter.toString();
parsed = WrapperInterfaceUUT__JsonHelper.parseFromJson(serialized);
assertNotNull(parsed);
assertTrue(parsed.mInterfaceParentWithWrapper instanceof InterfaceImplementation2UUT);
InterfaceImplementation2UUT parsedObj2 = (InterfaceImplementation2UUT) parsed.mInterfaceParentWithWrapper;
assertEquals(obj2.mIntegerField, parsedObj2.mIntegerField);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class MalformedJsonTest method scalarInsteadOfArray.
@Test
public void scalarInsteadOfArray() throws IOException, JSONException {
final int intValue = 25;
final int integerValue = 37;
final String stringValue = "hello world\r\n\'\"";
final int subIntValue = 30;
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(SimpleParseUUT.INT_FIELD_NAME).value(intValue).key(SimpleParseUUT.INTEGER_FIELD_NAME).value(integerValue).key(SimpleParseUUT.STRING_FIELD_NAME).value(stringValue).key(SimpleParseUUT.INTEGER_LIST_FIELD_NAME).value(intValue).key(SimpleParseUUT.SUBOBJECT_FIELD_NAME).object().key(SimpleParseUUT.SubobjectParseUUT.INT_FIELD_NAME).value(subIntValue).endObject().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());
assertEquals(stringValue, uut.stringField);
assertNull(uut.integerListField);
assertSame(subIntValue, uut.subobjectField.intField);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project drill by apache.
the class Metadata method writeFile.
/**
* Serialize parquet metadata to json and write to a file.
*
* @param parquetMetadata parquet table or directory metadata
* @param p file path
* @param fs Drill file system
* @throws IOException if metadata can't be serialized
*/
private void writeFile(Object parquetMetadata, Path p, FileSystem fs) throws IOException {
JsonFactory jsonFactory = new JsonFactory();
jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
ObjectMapper mapper = new ObjectMapper(jsonFactory);
SimpleModule module = new SimpleModule();
module.addSerializer(Path.class, new PathSerDe.Se());
if (parquetMetadata instanceof Metadata_V4.FileMetadata) {
module.addSerializer(ColumnMetadata_v4.class, new ColumnMetadata_v4.Serializer());
}
mapper.registerModule(module);
OutputStream os = fs.create(p);
mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetMetadata);
os.flush();
os.close();
}
Aggregations