Search in sources :

Example 56 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project build-info by JFrogDev.

the class BuildInfoExtractorUtils method jsonStringToGeneric.

public static <T extends Serializable> T jsonStringToGeneric(String json, Class<T> clazz) throws IOException {
    JsonFactory jsonFactory = createJsonFactory();
    JsonParser parser = jsonFactory.createJsonParser(new StringReader(json));
    return jsonFactory.getCodec().readValue(parser, clazz);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 57 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project build-info by JFrogDev.

the class BuildInfoExtractorUtils method buildInfoToJsonString.

public static String buildInfoToJsonString(Build buildInfo) throws IOException {
    JsonFactory jsonFactory = createJsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeObject(buildInfo);
    String result = writer.getBuffer().toString();
    return result;
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 58 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project api-core by ca-cwds.

the class ErrorMessageSerializerTest method setup.

@Before
public void setup() throws Exception {
    jsonWriter = new StringWriter();
    jsonGenerator = new JsonFactory().createGenerator(jsonWriter);
    serializerProvider = new ObjectMapper().getSerializerProvider();
    validationError = new ErrorMessage(ErrorMessage.ErrorType.VALIDATION, "not valid", "backend validation");
    businessError = new ErrorMessage(ErrorMessage.ErrorType.BUSINESS, "Can't do that", "buisness rule");
    messages = new HashSet<ErrorMessage>();
    messages.add(validationError);
    messages.add(businessError);
    writer = new ErrorMessageSerializer();
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 59 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project JavaForFun by gumartinm.

the class JacksonStreamingTestMain method main.

public static void main(final String[] args) throws JsonParseException, IOException {
    // Searching by geographic coordinates:
    // http://api.openweathermap.org/data/2.5/weather?lat=57&lon=-2.15&cnt=1
    final String dataA = "{" + "\"coord\":{\"lon\":139,\"lat\":35}," + "\"sys\":{\"message\":5.2147,\"country\":\"JP\",\"sunrise\":1397161018,\"sunset\":1397207585}," + "\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"Sky is Clear\",\"icon\":\"01n\"}]," + "\"base\":\"cmc stations\"," + "\"main\":{\"temp\":273.275,\"temp_min\":273.275,\"temp_max\":273.275,\"pressure\":988.56,\"sea_level\":1033.79,\"grnd_level\":988.56,\"humidity\":95}," + "\"wind\":{\"speed\":1.11,\"deg\":64.5043}," + "\"clouds\":{\"all\":0}," + "\"dt\":1397227133," + "\"rain\":{\"3h\":0}," + "\"id\":1851632," + "\"name\":\"Shuzenji\"," + "\"cod\":200" + "}";
    final String dataB = "{" + "\"coord\":{\"lon\":139,\"lat\":35}," + "\"wind\":{\"speed\":1.11,\"deg\":64.5043}," + "\"name\":\"Shuzenji\"," + "\"cod\":200" + "}";
    // Getting daily forecast weather data: Searching 15 days forecast by
    // geographic coordinates at JSON format
    // http://api.openweathermap.org/data/2.5/forecast/daily?lat=57&lon=-2.15&cnt=15&mode=json
    final String dataForeCast = "{" + "\"cod\":\"200\"," + "\"message\":0.0048," + "\"city\":{\"id\":2641549,\"name\":\"Newtonhill\",\"coord\":{\"lon\":-2.15,\"lat\":57.033329},\"country\":\"GB\",\"population\":0}," + "\"cnt\":15," + "\"list\":[" + "{\"dt\":1397304000,\"temp\":{\"day\":286.15,\"min\":284.62,\"max\":286.15,\"night\":284.62,\"eve\":285.7,\"morn\":286.15},\"pressure\":1016.67,\"humidity\":84,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.68,\"deg\":252,\"clouds\":0,\"rain\":0.25}," + "{\"dt\":1397390400,\"temp\":{\"day\":284.92,\"min\":282.3,\"max\":284.92,\"night\":282.3,\"eve\":283.79,\"morn\":284.24},\"pressure\":1021.62,\"humidity\":84,\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"speed\":7.91,\"deg\":259,\"clouds\":92}," + "{\"dt\":1397476800,\"temp\":{\"day\":282.1,\"min\":280.32,\"max\":282.1,\"night\":280.32,\"eve\":281.51,\"morn\":281.65},\"pressure\":1033.84,\"humidity\":92,\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"speed\":8.37,\"deg\":324,\"clouds\":20}," + "{\"dt\":1397563200,\"temp\":{\"day\":280.73,\"min\":280.11,\"max\":281.4,\"night\":281.4,\"eve\":280.75,\"morn\":280.11},\"pressure\":1039.27,\"humidity\":97,\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"speed\":7.31,\"deg\":184,\"clouds\":12}," + "{\"dt\":1397649600,\"temp\":{\"day\":281.73,\"min\":281.03,\"max\":282.22,\"night\":281.69,\"eve\":282.22,\"morn\":281.03},\"pressure\":1036.05,\"humidity\":90,\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"speed\":7.61,\"deg\":205,\"clouds\":68}," + "{\"dt\":1397736000,\"temp\":{\"day\":282.9,\"min\":281.45,\"max\":283.21,\"night\":282.71,\"eve\":283.06,\"morn\":281.49},\"pressure\":1029.39,\"humidity\":83,\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"speed\":6.17,\"deg\":268,\"clouds\":56}," + "{\"dt\":1397822400,\"temp\":{\"day\":285.26,\"min\":281.55,\"max\":285.26,\"night\":282.48,\"eve\":285.09,\"morn\":281.55},\"pressure\":1025.83,\"humidity\":0,\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"01d\"}],\"speed\":5.31,\"deg\":221,\"clouds\":10}," + "{\"dt\":1397908800,\"temp\":{\"day\":284.29,\"min\":281.5,\"max\":284.29,\"night\":282.53,\"eve\":283.58,\"morn\":281.5},\"pressure\":1024.55,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":5.51,\"deg\":192,\"clouds\":6}," + "{\"dt\":1397995200,\"temp\":{\"day\":283.36,\"min\":281.62,\"max\":284.34,\"night\":284.04,\"eve\":284.34,\"morn\":281.62},\"pressure\":1019.58,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.66,\"deg\":149,\"clouds\":0,\"rain\":0.48}," + "{\"dt\":1398081600,\"temp\":{\"day\":282.24,\"min\":280.51,\"max\":282.41,\"night\":280.51,\"eve\":282.41,\"morn\":280.9},\"pressure\":1027.35,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":8.17,\"deg\":221,\"clouds\":10,\"rain\":0.94}," + "{\"dt\":1398168000,\"temp\":{\"day\":282.28,\"min\":279.76,\"max\":282.28,\"night\":280.69,\"eve\":281.13,\"morn\":279.76},\"pressure\":1038.31,\"humidity\":0,\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"01d\"}],\"speed\":6.33,\"deg\":172,\"clouds\":1}," + "{\"dt\":1398254400,\"temp\":{\"day\":281.54,\"min\":280.52,\"max\":281.54,\"night\":281.44,\"eve\":281.23,\"morn\":280.52},\"pressure\":1022.4,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.84,\"deg\":140,\"clouds\":91,\"rain\":1.24}," + "{\"dt\":1398340800,\"temp\":{\"day\":282.1,\"min\":280.66,\"max\":282.78,\"night\":280.97,\"eve\":282.78,\"morn\":280.66},\"pressure\":1013.39,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":9.43,\"deg\":164,\"clouds\":98,\"rain\":1.03}," + "{\"dt\":1398427200,\"temp\":{\"day\":282.11,\"min\":280.72,\"max\":282.32,\"night\":282.32,\"eve\":280.99,\"morn\":280.72},\"pressure\":1018.65,\"humidity\":0,\"weather\":[{\"id\":502,\"main\":\"Rain\",\"description\":\"heavy intensity rain\",\"icon\":\"10d\"}],\"speed\":5.26,\"deg\":158,\"clouds\":83,\"rain\":14.4}," + "{\"dt\":1398513600,\"temp\":{\"day\":282.75,\"min\":280.61,\"max\":282.75,\"night\":280.61,\"eve\":281.75,\"morn\":281.96},\"pressure\":1007.4,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":9.18,\"deg\":198,\"clouds\":35,\"rain\":0.55}" + "]}";
    final JsonFactory f = new JsonFactory();
    CurrentWeatherData currentWeatherData = new CurrentWeatherData();
    currentWeatherData.setClouds(new Clouds());
    currentWeatherData.setCoord(new Coord());
    currentWeatherData.setMain(new Main());
    currentWeatherData.setRain(new Rain());
    currentWeatherData.setSys(new Sys());
    currentWeatherData.setWeather(new ArrayList<de.example.jackson.auto.currentweather.Weather>());
    currentWeatherData.setWind(new Wind());
    JsonParser jParser = f.createParser(dataA);
    System.out.println("DATAA UNMARSHALLING (JSON TO JAVA)");
    getCurrentWeatherData(currentWeatherData, jParser);
    printCurrentWeatherData(currentWeatherData);
    currentWeatherData = new CurrentWeatherData();
    currentWeatherData.setClouds(new Clouds());
    currentWeatherData.setCoord(new Coord());
    currentWeatherData.setMain(new Main());
    currentWeatherData.setRain(new Rain());
    currentWeatherData.setSys(new Sys());
    currentWeatherData.setWeather(new ArrayList<de.example.jackson.auto.currentweather.Weather>());
    currentWeatherData.setWind(new Wind());
    jParser = f.createParser(dataB);
    System.out.println();
    System.out.println();
    System.out.println("DATAB UNMARSHALLING (JSON TO JAVA)");
    getCurrentWeatherData(currentWeatherData, jParser);
    printCurrentWeatherData(currentWeatherData);
    System.out.println();
    System.out.println();
    final ForecastWeatherData forecastWeatherData = new ForecastWeatherData();
    forecastWeatherData.setList(new ArrayList<List>(15));
    final City city = new City();
    city.setCoord(new de.example.jackson.auto.forecast.Coord());
    forecastWeatherData.setCity(city);
    jParser = f.createParser(dataForeCast);
    System.out.println("FORECASTWEATHER UNMARSHALLING (JSON TO JAVA)");
    getForecastWeatherData(forecastWeatherData, jParser);
    printForecastWeatherData(forecastWeatherData);
}
Also used : Wind(de.example.jackson.auto.currentweather.Wind) Clouds(de.example.jackson.auto.currentweather.Clouds) JsonFactory(com.fasterxml.jackson.core.JsonFactory) City(de.example.jackson.auto.forecast.City) Sys(de.example.jackson.auto.currentweather.Sys) Coord(de.example.jackson.auto.currentweather.Coord) Rain(de.example.jackson.auto.currentweather.Rain) List(de.example.jackson.auto.forecast.List) ArrayList(java.util.ArrayList) ForecastWeatherData(de.example.jackson.auto.forecast.ForecastWeatherData) CurrentWeatherData(de.example.jackson.auto.currentweather.CurrentWeatherData) Main(de.example.jackson.auto.currentweather.Main) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 60 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project drill by axbaretto.

the class Metadata method writeFile.

/**
 * Serialize parquet metadata to json and write to a file
 *
 * @param parquetTableMetadata
 * @param p
 * @throws IOException
 */
private void writeFile(ParquetTableMetadata_v3 parquetTableMetadata, Path p) 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(ColumnMetadata_v3.class, new ColumnMetadata_v3.Serializer());
    mapper.registerModule(module);
    FSDataOutputStream os = fs.create(p);
    mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetTableMetadata);
    os.flush();
    os.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)266 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)102 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)91 JsonParser (com.fasterxml.jackson.core.JsonParser)78 Test (org.junit.Test)65 IOException (java.io.IOException)62 StringWriter (java.io.StringWriter)60 Map (java.util.Map)27 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 List (java.util.List)18 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)16 JsonToken (com.fasterxml.jackson.core.JsonToken)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 File (java.io.File)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 InputStreamReader (java.io.InputStreamReader)9 TypeReference (com.fasterxml.jackson.core.type.TypeReference)8 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8