List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:test.com.wealdtech.jackson.modules.MiscModuleTest.java
@Test public void testDeserRange() throws Exception { final String ser = "\"[2013-01-02T03:00:00Z Europe/London,2013-01-02T04:00:00Z Europe/London)\""; final Range<DateTime> deser = this.mapper.readValue(ser, new TypeReference<Range<DateTime>>() { });/*from www.j a va 2s.co m*/ assertEquals(deser, Range.closedOpen( new DateTime(2013, 1, 2, 3, 0, 0).withZoneRetainFields(DateTimeZone.forID("Europe/London")), new DateTime(2013, 1, 2, 4, 0, 0).withZoneRetainFields(DateTimeZone.forID("Europe/London")))); }
From source file:org.saltyrtc.client.helpers.MessageReader.java
/** * Read MessagePack bytes, return a Message subclass instance. * @param bytes Messagepack bytes./*from w ww . j ava2 s . c om*/ * @param taskTypes List of message types supported by task. * @return Message subclass instance. * @throws SerializationError Thrown if deserialization fails. * @throws ValidationError Thrown if message can be deserialized but is invalid. */ public static Message read(byte[] bytes, List<String> taskTypes) throws SerializationError, ValidationError { // Unpack data into map ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); Map<String, Object> map; try { map = objectMapper.readValue(bytes, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { throw new SerializationError("Deserialization failed", e); } // Get type value if (!map.containsKey("type")) { throw new SerializationError("Message does not contain a type field"); } Object typeObj = map.get("type"); if (!(typeObj instanceof String)) { throw new SerializationError("Message type must be a string"); } String type = (String) typeObj; // Dispatch message instantiation switch (type) { case "server-hello": return new ServerHello(map); case "client-hello": return new ClientHello(map); case "server-auth": if (map.containsKey("initiator_connected")) { return new ResponderServerAuth(map); } else if (map.containsKey("responders")) { return new InitiatorServerAuth(map); } throw new ValidationError("Invalid server-auth message"); case "client-auth": return new ClientAuth(map); case "new-initiator": return new NewInitiator(map); case "new-responder": return new NewResponder(map); case "drop-responder": return new DropResponder(map); case "send-error": return new SendError(map); case "token": return new Token(map); case "key": return new Key(map); case "auth": if (map.containsKey("task")) { return new InitiatorAuth(map); } else if (map.containsKey("tasks")) { return new ResponderAuth(map); } throw new ValidationError("Invalid auth message"); case "close": return new Close(map); case "application": return new Application(map); default: if (taskTypes.contains(type)) { return new TaskMessage(type, map); } throw new ValidationError("Unknown message type: " + type); } }
From source file:org.javafunk.funk.jackson.monad.OptionDeserializerTest.java
@Test public void shouldDeserializeComplexObject() throws Exception { // Given//w ww.j av a 2 s.c om TypeReference<Option<OptionData>> type = new TypeReference<Option<OptionData>>() { }; // When Option<OptionData> data = objectMapper.readValue("{\"myString\":\"simpleString\"}", type); // Then assertThat(data, OptionMatchers.<OptionData>hasValue()); assertThat(data.get().myString, hasValue("simpleString")); }
From source file:cz.muni.fi.pa165.bookingmanager.desktop.rest.UserRESTManager.java
public List<UserTO> findAllUsers() { List<UserTO> users = new ArrayList<>(); String json = webResource.path("users/").accept(MediaType.APPLICATION_JSON).get(String.class); try {//from www .ja v a 2s .c o m users = mapper.readValue(json, new TypeReference<List<UserTO>>() { }); } catch (IOException e) { Logger.getLogger(UserRESTManager.class.getName()).log(Level.SEVERE, null, e); } return users; }
From source file:com.vmware.photon.controller.api.client.resource.AuthApi.java
/** * Get auth status asynchronously.//from w w w . j av a2s . co m * * @param responseCallback * @throws IOException */ public void getAuthStatusAsync(final FutureCallback<Auth> responseCallback) throws IOException { String path = getBasePath(); getObjectByPathAsync(path, responseCallback, new TypeReference<Auth>() { }); }
From source file:com.netflix.edda.EddaEc2Client.java
public DescribeClassicLinkInstancesResult describeClassicLinkInstances( DescribeClassicLinkInstancesRequest request) { validateEmpty("Filter", request.getFilters()); TypeReference<List<ClassicLinkInstance>> ref = new TypeReference<List<ClassicLinkInstance>>() { };/* w ww . j ava 2 s.co m*/ String url = config.url() + "/api/v2/aws/classicLinkInstances;_expand"; try { List<ClassicLinkInstance> instances = parse(ref, doGet(url)); List<String> ids = request.getInstanceIds(); if (shouldFilter(ids)) { List<ClassicLinkInstance> is = new ArrayList<ClassicLinkInstance>(); for (ClassicLinkInstance i : instances) { if (matches(ids, i.getInstanceId())) is.add(i); } instances = is; } return new DescribeClassicLinkInstancesResult().withInstances(instances); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:fi.helsinki.opintoni.integration.unisport.UnisportMockClient.java
@Override public UnisportUserReservations getUserReservations(Long unisportUserId, Locale locale) { return getResponse(userReservationsResource, new TypeReference<UnisportUserReservations>() { });/*from www. j a va 2 s .co m*/ }
From source file:com.vmware.photon.controller.nsxclient.apis.DhcpServiceApi.java
/** * Creates a DHCP relay service profile. */// ww w .j av a 2 s . c om public void createDhcpRelayProfile(DhcpRelayProfileCreateSpec request, FutureCallback<DhcpRelayProfile> responseCallback) throws IOException { postAsync(SERVICE_PROFILES_BASE_PATH, serializeObjectAsJson(request), HttpStatus.SC_CREATED, new TypeReference<DhcpRelayProfile>() { }, responseCallback); }
From source file:com.vmware.photon.controller.api.client.resource.DisksApi.java
/** * Get details about the specified disk. * * @param diskId/*from w w w . j a v a 2 s . co m*/ * @return Disk details * @throws java.io.IOException */ public PersistentDisk getDisk(String diskId) throws IOException { String path = String.format("%s/%s", getBasePath(), diskId); HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null); this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK); return this.restClient.parseHttpResponse(httpResponse, new TypeReference<PersistentDisk>() { }); }
From source file:com.github.nmorel.gwtjackson.guava.jackson.ImmutablesJacksonTest.java
@Test public void testImmutableSetFromSingle() { objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); objectMapper.enable(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED); ImmutablesTester.INSTANCE/*from w w w . ja v a 2 s . co m*/ .testImmutableSetFromSingle(createMapper(new TypeReference<ImmutableSet<String>>() { })); }