Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:com.damnhandy.uri.template.JsonVarExploder.java

private void initValues() throws VarExploderException {
    ObjectMapper mapper = new ObjectMapper();
    try {/*from  w w w. jav  a2 s  .co  m*/
        values = mapper.readValue(source, new TypeReference<Map<String, Object>>() {
        });
    } catch (JsonParseException e) {
        throw new VarExploderException(e);
    } catch (JsonMappingException e) {
        throw new VarExploderException(e);
    } catch (IOException e) {
        throw new VarExploderException(e);
    }
}

From source file:com.vmware.photon.controller.api.client.resource.TasksRestApi.java

/**
 * Get task details asynchronously.//from  w w w  .  j  a  v a2s  . com
 *
 * @param taskId
 * @param responseCallback
 * @throws IOException
 */
@Override
public void getTaskAsync(final String taskId, final FutureCallback<Task> responseCallback) throws IOException {
    String path = getBasePath() + "/" + taskId;

    getObjectByPathAsync(path, responseCallback, new TypeReference<Task>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.DisksApi.java

/**
 * This method get a disk object./*from  w w w .  j  av  a  2 s  .  c om*/
 *
 * @param diskId
 * @param responseCallback
 * @throws IOException
 */
public void getDiskAsync(final String diskId, final FutureCallback<PersistentDisk> responseCallback)
        throws IOException {
    String path = String.format("%s/%s", getBasePath(), diskId);

    getObjectByPathAsync(path, responseCallback, new TypeReference<PersistentDisk>() {
    });
}

From source file:com.okta.sdk.clients.SessionApiClient.java

public Session createSessionWithCredentialsAndAdditionalFields(String username, String password,
        String additionalFields) throws IOException {
    Credentials credentials = new Credentials();
    credentials.setUsername(username);/*from   w ww.  java 2  s.com*/
    credentials.setPassword(password);
    return post(getEncodedPath("?additionalFields=%s", additionalFields), credentials,
            new TypeReference<Session>() {
            });
}

From source file:org.javafunk.funk.jackson.monad.OptionDeserializerTest.java

@Test
public void shouldDeserializeGenerics() throws Exception {
    // Given/*from w ww . ja  va 2 s . com*/
    TypeReference<Option<GenericData<String>>> type = new TypeReference<Option<GenericData<String>>>() {
    };

    // When
    Option<GenericData<String>> data = objectMapper.readValue("{\"myData\":\"simpleString\"}", type);

    // Then
    assertThat(data, OptionMatchers.<GenericData<String>>hasValue());
    assertThat(data.get().myData, hasValue("simpleString"));
}

From source file:fi.helsinki.opintoni.integration.coursepage.CoursePageMockClient.java

@Override
public List<CoursePageNotification> getCoursePageNotifications(Set<String> courseImplementationIds,
        LocalDateTime from, Locale locale) {
    return getResponse(notifications, new TypeReference<List<CoursePageNotification>>() {
    });//from   www . j av a  2  s  . com
}

From source file:com.excilys.spring.mom.parser.MOMResponseJSONAttributesParser.java

@Override
public Object[] parse(byte[] data) throws MOMResponseParsingException {
    if (data == null || data.length == 0) {
        throw new MOMResponseParsingException("The json string is empty");
    }/* w w  w .j  a v  a2s.  c  o m*/

    List<Object> results = new ArrayList<Object>();
    Map<String, Object> jsonMap;

    try {
        jsonMap = ObjectMapperSingleton.INSTANCE.getMapper().readValue(data,
                new TypeReference<Map<String, Object>>() {
                });
    } catch (IOException e) {
        throw new MOMResponseParsingException("Unable to parse the json string : " + new String(data), e);
    }

    // For each annotated parameter, try to get back the json value according to the key
    for (ParameterInfo bindAttribute : bindAttributes) {
        Object attributeValue = jsonMap.get(bindAttribute.getName());

        // Decode a base64 encoded string
        if (bindAttribute.getEncoding() == MOMAttributeEncoding.BASE64) {
            if (attributeValue instanceof String) {
                attributeValue = Base64.decodeBase64((String) attributeValue);
            } else if (attributeValue instanceof byte[]) {
                attributeValue = Base64.decodeBase64((byte[]) attributeValue);
            }
        }

        if (attributeValue != null) {
            results.add(attributeValue);
        }
    }

    return results.toArray();
}

From source file:retsys.client.controller.VendorController.java

/**
 * Initializes the controller class.//  ww w .jav  a 2s .c  o m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    AutoCompletionBinding<Vendor> txt_name = TextFields.bindAutoCompletion(name,
            new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Vendor>>() {

                @Override
                public Collection<Vendor> call(AutoCompletionBinding.ISuggestionRequest param) {
                    List<Vendor> list = null;
                    HttpHelper helper = new HttpHelper();
                    try {
                        LovHandler lovHandler = new LovHandler("vendors", "name");
                        String response = lovHandler.getSuggestions(param.getUserText());
                        list = (List<Vendor>) new JsonHelper().convertJsonStringToObject(response,
                                new TypeReference<List<Vendor>>() {
                                });
                    } catch (IOException ex) {
                        Logger.getLogger(VendorController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    return list;
                }

            }, new StringConverter<Vendor>() {

                @Override
                public String toString(Vendor object) {
                    return object.getName() + " (ID:" + object.getId() + ")";
                }

                @Override
                public Vendor fromString(String string) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            });

    //event handler for setting other Client fields with values from selected Client object
    //fires after autocompletion
    txt_name.setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<Vendor>>() {

        @Override
        public void handle(AutoCompletionBinding.AutoCompletionEvent<Vendor> event) {
            Vendor vendor = event.getCompletion();
            //fill other item related fields
            id.setText(splitId(name.getText()) + "");
            name.setText(vendor.getName());
            address.setText(vendor.getAddress());
            phone.setText(vendor.getPhone());
            mobile.setText(vendor.getMobile());
            remarks.setText(vendor.getRemarks());
            email.setText(vendor.getEmail());

            populateAuditValues(vendor);
        }
    });
}

From source file:com.navercorp.pinpoint.web.vo.AgentDownloadInfoTest.java

@Test
public void defaultTest() throws Exception {
    String mockResponseString = getMockJsonString();

    ObjectMapper objectMapper = new ObjectMapper();
    TypeReference<List<GithubAgentDownloadInfo>> typeReference = new TypeReference<List<GithubAgentDownloadInfo>>() {
    };// w  w w .  j a  va2s.  c o m
    List<GithubAgentDownloadInfo> agentDownloadInfoList = objectMapper.readValue(mockResponseString,
            typeReference);

    Assert.assertEquals(15, agentDownloadInfoList.size());
}

From source file:retsys.client.controller.ProductController.java

/**
 * Initializes the controller class./*  w w  w . j a v a  2 s  .  co m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    AutoCompletionBinding<Product> txt_name = TextFields.bindAutoCompletion(name,
            new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Product>>() {

                @Override
                public Collection<Product> call(AutoCompletionBinding.ISuggestionRequest param) {
                    List<Product> list = null;
                    HttpHelper helper = new HttpHelper();
                    try {
                        LovHandler lovHandler = new LovHandler("products", "name");
                        String response = lovHandler.getSuggestions(param.getUserText());
                        list = (List<Product>) new JsonHelper().convertJsonStringToObject(response,
                                new TypeReference<List<Product>>() {
                                });
                    } catch (IOException ex) {
                        Logger.getLogger(ProductController.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    return list;
                }

            }, new StringConverter<Product>() {

                @Override
                public String toString(Product object) {
                    return object.getName() + " (ID:" + object.getId() + ")";
                }

                @Override
                public Product fromString(String string) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            });

    //event handler for setting other Client fields with values from selected Client object
    //fires after autocompletion
    txt_name.setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<Product>>() {

        @Override
        public void handle(AutoCompletionBinding.AutoCompletionEvent<Product> event) {
            Product product = event.getCompletion();
            //fill other item related fields
            id.setText(String.valueOf(product.getId()));
            name.setText(product.getName());
            productDesc.setText(product.getProdDesc());
            remarks.setText(product.getRemarks());
            //desc.setText(product.getDesc());

            populateAuditValues(product);
        }
    });
}