List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:org.commonjava.maven.atlas.ident.jackson.ProjectVersionRefSerializerModuleTest.java
@Test public void mapWithProjectRefKeyRoundTrip() throws Exception { final ProjectRef pr = new SimpleProjectRef("org.foo", "bar"); final String value = "this is the value"; final Map<ProjectRef, String> map = new HashMap<ProjectRef, String>(); map.put(pr, value);/*from w w w. j av a2 s. c om*/ final String json = mapper.writeValueAsString(map); final Map<ProjectRef, String> result = mapper.readValue(json, new TypeReference<Map<ProjectRef, String>>() { }); assertThat(result.get(pr), equalTo(value)); }
From source file:alfio.model.TicketFieldConfigurationDescriptionAndValue.java
public List<TicketFieldValue> getFields() { if (count == 1) { return Collections.singletonList(new TicketFieldValue(0, 1, value)); }/* w w w.j a va 2s. c o m*/ List<String> values = StringUtils.isBlank(value) ? Collections.emptyList() : Json.fromJson(value, new TypeReference<List<String>>() { }); return IntStream.range(0, count) .mapToObj(i -> new TicketFieldValue(i, i + 1, i < values.size() ? values.get(i) : "")) .collect(Collectors.toList()); }
From source file:test.com.wealdtech.jackson.modules.WIDModuleTest.java
@Test public void testDeserWIDMap() throws Exception { final String ser = "{\"a2a19b20000000a\":\"Test\"}"; final Map<WID<Date>, String> deser = this.mapper.readValue(ser, new TypeReference<HashMap<WID<Date>, String>>() { });/*from w w w .j a v a 2 s.co m*/ assertNotNull(deser); assertEquals(deser.size(), 1); assertNotNull(deser.get(WID.<Date>fromComponents(5, 1500000000000L, 10))); }
From source file:org.whispersystems.bithub.config.GithubConfiguration.java
public List<RepositoryConfiguration> getRepositories() { if (repositories != null) { return repositories; }//from ww w . java 2 s . c o m if (repositories_heroku != null) { try { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(repositories_heroku, new TypeReference<List<RepositoryConfiguration>>() { }); } catch (IOException e) { logger.warn("Error deserializing", e); } } return new LinkedList<>(); }
From source file:javaslang.jackson.datatype.PolymorphicTypesTest.java
@Test public void deserializeList() throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaslangModule()); List<I> i = mapper.readerFor(new TypeReference<List<I>>() { }).readValue("[{\"type\":\"a\"},{\"type\":\"b\"}]"); Assert.assertTrue(i.nonEmpty());/*from w ww. j a v a 2 s .co m*/ Assert.assertTrue(i.get(0) instanceof A); Assert.assertTrue(i.get(1) instanceof B); }
From source file:uk.co.sdev.async.http.ning.CompletableFutureClientTest.java
private CompletableFuture<Optional<Bar>> getOptionalBar() throws IOException { return completableFutureClient.get("http://localhost:9101/bar", new TypeReference<Optional<Bar>>() { });//from w w w.j a v a 2 s.co m }
From source file:org.mayocat.attachment.store.jdbi.mapper.LoadedAttachmentMapper.java
@Override public LoadedAttachment map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { LoadedAttachment attachment = new LoadedAttachment(); attachment.setId((UUID) resultSet.getObject("id")); attachment.setTitle(resultSet.getString("title")); attachment.setDescription(resultSet.getString("description")); attachment.setSlug(resultSet.getString("slug")); attachment.setData(new AttachmentData(resultSet.getBinaryStream("data"))); attachment.setExtension(resultSet.getString("extension")); attachment.setParentId((UUID) resultSet.getObject("parent_id")); ObjectMapper mapper = new ObjectMapper(); if (!Strings.isNullOrEmpty(resultSet.getString("metadata"))) { try {/*from ww w . j a v a 2s . c o m*/ Map<String, Map<String, Object>> metadata = mapper.readValue(resultSet.getString("metadata"), new TypeReference<Map<String, Map<String, Object>>>() { }); attachment.setMetadata(metadata); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } if (MapperUtils.hasColumn("localization_data", resultSet) && !Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { try { Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } attachment.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } return attachment; }
From source file:com.nesscomputing.jackson.TestMapEntryDeserialization.java
@Test public void testMapEntryNullKeySerialization() throws Exception { Entry<String, Integer> entry = Maps.immutableEntry(null, 3); assertEquals(entry,/*from w ww . j av a2 s . c o m*/ mapper.readValue(mapper.writeValueAsString(entry), new TypeReference<Entry<String, Integer>>() { })); }
From source file:com.github.nmorel.gwtjackson.guava.jackson.OptionalJacksonTest.java
@Test public void testSerializeGeneric() { OptionalTester.INSTANCE//from ww w . j a va 2 s . co m .testSerializeGeneric(createWriter(new TypeReference<Optional<OptionalGenericData<String>>>() { })); }
From source file:com.addthis.bundle.util.AutoFieldTest.java
@Test public void createDerivedTyped() throws IOException { DerivedTypedField<List<String>> autoField = Jackson.defaultMapper().readValue("\"someField\"", new TypeReference<DerivedTypedField<List<String>>>() { });/*from ww w . j a va 2 s.co m*/ Bundle bundle = Bundles.decode("someField: [a, b, c]"); List<String> strings = autoField.getValue(bundle); assertEquals(Lists.newArrayList("a", "b", "c"), strings); }