List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:com.hp.autonomy.hod.client.converter.HodConverterTest.java
@Before public void setUp() { final ObjectMapper objectMapper = new ObjectMapper(); final JacksonConverter jacksonConverter = new JacksonConverter(objectMapper); this.hodConverter = new HodConverter(jacksonConverter); }
From source file:com.shampan.db.collections.fragment.status.UserInfo.java
public static UserInfo getUserInfo(String jsonContent) { UserInfo userInfo = null;/*from w w w. j a va 2 s . com*/ try { ObjectMapper mapper = new ObjectMapper(); userInfo = mapper.readValue(jsonContent, UserInfo.class); } catch (Exception ex) { ex.printStackTrace(); } return userInfo; }
From source file:com.yahoo.elide.jsonapi.models.PatchTest.java
@Test public void testSerialization() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode valueNode = mapper.readTree("\"stringValue\""); Patch patch = new Patch(Patch.Operation.ADD, "/foo/bar", valueNode); String expected = "{\"op\":\"add\",\"path\":\"/foo/bar\",\"value\":\"stringValue\"}"; String actual = mapper.writeValueAsString(patch); Assert.assertEquals(expected, actual, "A patch object should serialize correctly as a string."); }
From source file:com.boundary.sdk.snmp.metric.Pollers.java
public static Pollers load(String resource) throws URISyntaxException { Pollers instance = new Pollers(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {/*from w w w .ja va 2 s . c o m*/ instance = mapper.readValue(file, Pollers.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:com.hybridbpm.ui.component.chart.util.DiagrammeUtil.java
public static <T> T stringToObject(String json, Class<T> clazz) { T result = null;// www. ja va2 s. c o m try { ObjectMapper mapper = new ObjectMapper(); // mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); result = (T) mapper.readValue(json, clazz); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } return result; }
From source file:jenkins.plugins.sonarparser.SonarReportParser.java
public static SonarReport parse(InputStream input) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaDateTimeModule()); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); SonarReport report = mapper.readValue(input, SonarReport.class); return report; }
From source file:com.amazon.android.navigator.NavigatorModelParser.java
/** * Parses the Navigator JSON file into a {@link NavigatorModel} object. The JSON file is * defined/* ww w . j av a 2 s . co m*/ * by the {@link Navigator#NAVIGATOR_FILE} string. * * @param context The context. * @return A NavigatorModel object. */ public static NavigatorModel parse(Context context, String navigatorFile) { NavigatorModel navigatorModel = null; try { ObjectMapper objectMapper = new ObjectMapper(); String navigatorFileString = FileHelper.readFile(context, navigatorFile); navigatorModel = objectMapper.readValue(navigatorFileString, NavigatorModel.class); Log.v(TAG, "Navigator Model: " + navigatorModel.toString()); // Preload recipes for (NavigatorModel.GlobalRecipes globalRecipes : navigatorModel.getGlobalRecipes()) { // Load category recipes if there is no hard coded name defined. if (globalRecipes.getCategories() != null && globalRecipes.getCategories().name == null) { globalRecipes.getCategories().dataLoaderRecipe = Recipe.newInstance(context, globalRecipes.getCategories().dataLoader); globalRecipes.getCategories().dynamicParserRecipe = Recipe.newInstance(context, globalRecipes.getCategories().dynamicParser); } if (globalRecipes.getContents() != null) { globalRecipes.getContents().dataLoaderRecipe = Recipe.newInstance(context, globalRecipes.getContents().dataLoader); globalRecipes.getContents().dynamicParserRecipe = Recipe.newInstance(context, globalRecipes.getContents().dynamicParser); } } // Preload Recommendation recipes if (navigatorModel.getRecommendationRecipes() != null) { for (NavigatorModel.RecommendationRecipes recommendationRecipes : navigatorModel .getRecommendationRecipes()) { if (recommendationRecipes.getContents() != null) { recommendationRecipes.getContents().dataLoaderRecipe = Recipe.newInstance(context, recommendationRecipes.getContents().dataLoader); recommendationRecipes.getContents().dynamicParserRecipe = Recipe.newInstance(context, recommendationRecipes.getContents().dynamicParser); } } } } catch (Exception e) { Log.e(TAG, "Navigator parsing failed!!! ", e); } return navigatorModel; }
From source file:com.boundary.plugin.sdk.jmx.JMXPluginConfiguration.java
public static JMXPluginConfiguration getConfiguration() { ObjectMapper mapper = new ObjectMapper(); JMXPluginConfiguration configuration = null; try {/*from w w w .ja va 2 s . com*/ configuration = mapper.readValue(new File(PLUGIN_PARAMETER_FILENAME), JMXPluginConfiguration.class); } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return configuration; }
From source file:com.liscs.server.utils.JacksonUtils.java
public T stringToObject(String json, Class clazz) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try {// ww w . ja va 2 s. co m T result = (T) objectMapper.readValue(json, clazz); return result; } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:io.confluent.kafka.schemaregistry.zookeeper.SchemaRegistryIdentity.java
public static SchemaRegistryIdentity fromJson(String json) throws IOException { return new ObjectMapper().readValue(json, SchemaRegistryIdentity.class); }