Search in sources :

Example 26 with JsonWriter

use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.

the class SampleTest method testSample.

public void testSample() throws Exception {
    assertEquals(true, true);
    new JsonWriter(new StringWriter()).writeObject(12);
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(com.serotonin.json.JsonWriter)

Example 27 with JsonWriter

use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.

the class WriteTest method write.

static void write(Object o) throws Exception {
    StringWriter out = new StringWriter();
    JsonWriter writer = new JsonWriter(context, out);
    writer.writeObject(o);
    System.out.println(out);
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(com.serotonin.json.JsonWriter)

Example 28 with JsonWriter

use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.

the class ModulesController method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
    // Check for a license download token.
    String token = request.getParameter("token");
    if (!StringUtils.isEmpty(token)) {
        if (downloadLicense(token))
            model.put("licenseDownloaded", true);
    }
    List<Module> modules = ModuleRegistry.getModules();
    Module.sortByName(modules);
    Module core = ModuleRegistry.getCoreModule();
    modules.add(0, core);
    model.put("guid", Providers.get(ICoreLicense.class).getGuid());
    model.put("distributor", Common.envProps.getString("distributor"));
    model.put("modules", modules);
    // Add in the Unloaded modules
    model.put("unloadedModules", ModuleRegistry.getUnloadedModules());
    // The JSON
    Map<String, Object> json = new HashMap<>();
    json.put("guid", Providers.get(ICoreLicense.class).getGuid());
    json.put("description", SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
    json.put("distributor", Common.envProps.getString("distributor"));
    Map<String, String> jsonModules = new HashMap<>();
    json.put("modules", jsonModules);
    for (Module module : modules) {
        jsonModules.put(module.getName(), module.getVersion().toString());
    }
    try {
        StringWriter out = new StringWriter();
        JsonWriter jsonWriter = new JsonWriter(Common.JSON_CONTEXT, out);
        jsonWriter.writeObject(json);
        model.put("json", out.toString());
    } catch (Exception e) {
        throw new ShouldNeverHappenException(e);
    }
    return null;
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) Module(com.serotonin.m2m2.module.Module) JsonWriter(com.serotonin.json.JsonWriter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 29 with JsonWriter

use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.

the class AuditEventDao method writeValueAsString.

public String writeValueAsString(JsonObject value) throws JsonException, IOException {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
    writer.writeObject(value);
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(com.serotonin.json.JsonWriter)

Aggregations

JsonWriter (com.serotonin.json.JsonWriter)29 StringWriter (java.io.StringWriter)26 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)12 HttpPost (org.apache.http.client.methods.HttpPost)12 StringEntity (org.apache.http.entity.StringEntity)12 JsonArray (com.serotonin.json.type.JsonArray)10 JsonValue (com.serotonin.json.type.JsonValue)10 IOException (java.io.IOException)7 JsonException (com.serotonin.json.JsonException)6 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)5 HashMap (java.util.HashMap)4 Version (com.github.zafarkhaja.semver.Version)2 JsonContext (com.serotonin.json.JsonContext)2 JsonReader (com.serotonin.json.JsonReader)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonString (com.serotonin.json.type.JsonString)2 Module (com.serotonin.m2m2.module.Module)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 OutputStreamWriter (java.io.OutputStreamWriter)2 JsonRawValue (com.fasterxml.jackson.annotation.JsonRawValue)1