com.github.TKnudsen.ComplexDataObject.model.io.json.JSONLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
package com.github.TKnudsen.ComplexDataObject.model.io.json;
import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObject;
/**
*
* Title: JSONLoader
*
*
*
* Description: loads a ComplexDataObject from JSON
*
*
*
* Copyright: Copyright (c) 2017
*
*
* @author Juergen Bernard
* @version 1.0
*/
public class JSONLoader {
public static ComplexDataObject loadFromString(String json) {
ObjectMapper mapper = ObjectMapperFactory.getComplexDataObjectObjectMapper();
ComplexDataObject complexDataObject;
try {
complexDataObject = mapper.readValue(json, ComplexDataObject.class);
return complexDataObject;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static ComplexDataObject loadFromFile(String file) {
ObjectMapper mapper = ObjectMapperFactory.getComplexDataObjectObjectMapper();
ComplexDataObject complexDataObject;
try {
complexDataObject = mapper.readValue(new File(file), ComplexDataObject.class);
return complexDataObject;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}