Search in sources :

Example 1 with JSONSerializationProvider

use of com.datatorrent.stram.util.JSONSerializationProvider in project apex-core by apache.

the class AppPackageTest method testPropertyInfoSerializer.

@Test
public void testPropertyInfoSerializer() throws JsonGenerationException, JsonMappingException, IOException {
    AppPackage.PropertyInfo propertyInfo = new AppPackage.PropertyInfo("test-value", "test-description");
    JSONSerializationProvider jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(false));
    String result = jomp.getContext(null).writeValueAsString(propertyInfo);
    Assert.assertEquals("\"test-value\"", result);
    jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(true));
    result = jomp.getContext(null).writeValueAsString(propertyInfo);
    Assert.assertEquals("{\"value\":\"test-value\",\"description\":\"test-description\"}", result);
}
Also used : PropertyInfo(com.datatorrent.stram.client.AppPackage.PropertyInfo) JSONSerializationProvider(com.datatorrent.stram.util.JSONSerializationProvider) PropertyInfo(com.datatorrent.stram.client.AppPackage.PropertyInfo) Test(org.junit.Test)

Example 2 with JSONSerializationProvider

use of com.datatorrent.stram.util.JSONSerializationProvider in project apex-core by apache.

the class AppPackageTest method starting.

@BeforeClass
public static void starting() throws IOException, JSONException {
    File file = StramTestSupport.createAppPackageFile();
    // Set up test instance
    ap = new AppPackage(file, true);
    try {
        // set up another instance
        File testfolder = new File("target/testapp");
        yap = new AppPackage(file, testfolder, false);
        jomp = new JSONSerializationProvider();
        json = new JSONObject(jomp.getContext(null).writeValueAsString(ap));
    } finally {
        IOUtils.closeQuietly(ap);
        IOUtils.closeQuietly(yap);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONSerializationProvider(com.datatorrent.stram.util.JSONSerializationProvider) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

JSONSerializationProvider (com.datatorrent.stram.util.JSONSerializationProvider)2 PropertyInfo (com.datatorrent.stram.client.AppPackage.PropertyInfo)1 File (java.io.File)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1