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:org.springframework.cloud.stream.endpoint.ChannelsEndpoint.java

@Override
public Map<String, Object> invoke() {
    ChannelsMetaData map = new ChannelsMetaData();
    Map<String, BindingProperties> inputs = map.getInputs();
    Map<String, BindingProperties> outputs = map.getOutputs();
    for (Bindable factory : this.adapters) {
        for (String name : factory.getInputs()) {
            inputs.put(name, this.properties.getBindingProperties(name));
        }/*from   ww  w .j  a  v a 2s . c om*/
        for (String name : factory.getOutputs()) {
            outputs.put(name, this.properties.getBindingProperties(name));
        }
    }
    return new ObjectMapper().convertValue(map, new TypeReference<Map<String, Object>>() {
    });
}

From source file:rest.ShipmentREST.java

private Shipment getFormattedDataSingle(Response response) {
    String responseJson = response.readEntity(String.class);
    System.out.println(responseJson);
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {
    };/*from w w  w .j av  a  2s.  c  om*/
    StringBuilder sb = new StringBuilder();
    try {
        HashMap<String, Object> map = mapper.readValue(responseJson, typeReference);
        if (Boolean.parseBoolean(map.get("found").toString())) {
            return Shipment.parseShipment(map);
            //               
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}

From source file:com.htmlhifive.pitalium.core.selenium.PtlCapabilities.java

/**
 * Capabilities????????//from   w w w . ja  v  a 2  s  .  co m
 * 
 * @param filePath 
 * @return ??Capabilities
 */
static List<Map<String, Object>> readCapabilitiesFromFileOrResources(String filePath) {
    LOG.trace("Load capabilities. ({})", filePath);

    TypeReference<List<Map<String, Object>>> reference = new TypeReference<List<Map<String, Object>>>() {
    };
    try {
        // Read from file
        return JSONUtils.readValue(new File(filePath), reference);
    } catch (JSONException e) {
        // Read from resources
        InputStream in = null;
        try {
            in = PtlCapabilities.class.getClassLoader().getResourceAsStream(filePath);
            return JSONUtils.readValue(in, reference);
        } catch (Exception e1) {
            throw new TestRuntimeException("Failed to load capabilities", e1);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ioe) {
                    LOG.error("", ioe);
                }
            }
        }
    }
}

From source file:com.netflix.suro.sink.localfile.TestLocalFileSink.java

@Test
public void testDefaultParameters() throws IOException {
    String testdir = tempDir.newFolder().getAbsolutePath();

    final String localFileSinkSpec = "{\n" + "    \"type\": \"" + LocalFileSink.TYPE + "\",\n"
            + "    \"outputDir\": \"" + testdir + "\"\n" + "    }\n" + "}";

    ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    Sink sink = mapper.readValue(localFileSinkSpec, new TypeReference<Sink>() {
    });//from  w  ww .  j a v a 2 s.c  o m
    sink.open();

    assertNull(sink.recvNotice());

    for (Message m : new MessageSetReader(TestConnectionPool.createMessageSet(10000))) {
        sink.writeTo(new StringMessage(m));
    }

    sink.close();

    System.out.println(sink.getStat());

    int count = 0;
    File dir = new File(testdir);
    File[] files = dir.listFiles();
    for (File file : files) {
        assertTrue(file.getName().contains(".done"));
        if (!file.getName().contains("crc")) {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line = null;
            while ((line = br.readLine()) != null) {
                assertTrue(line.contains("testMessage"));
                ++count;
            }
            br.close();
        }
    }
    assertEquals(count, 10000);
}

From source file:rest.ChecklistREST.java

private Checklist getFormattedDataSingle(Response response) {
    String responseJson = response.readEntity(String.class);
    System.out.println(responseJson);
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {
    };/*  ww w  . j a v a2 s. c om*/
    StringBuilder sb = new StringBuilder();
    try {
        HashMap<String, Object> map = mapper.readValue(responseJson, typeReference);
        if (Boolean.parseBoolean(map.get("found").toString())) {
            return Checklist.parseChecklist(map);
            //               
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}

From source file:com.infinities.nova.policy.Rules.java

public static Rules loadJson(String data, Object defaultRule) throws IOException {
    Map<String, String> map = JsonUtil.readJson(data, new TypeReference<LinkedHashMap<String, String>>() {
    });//from   www  .java 2  s .  c  o  m

    Map<String, BaseCheck> rules = Maps.newHashMap();
    for (Entry<String, String> entry : map.entrySet()) {
        logger.debug("put rules key:{}, value:{} ", new Object[] { entry.getKey(), entry.getValue() });
        rules.put(entry.getKey(), parseRule(entry.getValue()));
    }

    return new Rules(rules, defaultRule);
}

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

/**
 * This method get a disk object.// www.  ja va 2s  . c  o m
 *
 * @param diskId
 * @param responseCallback
 * @throws IOException
 */
@Override
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:test.com.wealdtech.jackson.modules.MiscModuleTest.java

@Test
public void testDeserUnboundedRange() throws Exception {
    final String ser = "\"[2013-01-02T03:00:00+13:45 Pacific/Chatham,+)\"";
    final Range<DateTime> deser = this.mapper.readValue(ser, new TypeReference<Range<DateTime>>() {
    });//  w  ww. jav a  2s . c  o m
    assertEquals(deser, Range.atLeast(
            new DateTime(2013, 1, 2, 3, 0, 0).withZoneRetainFields(DateTimeZone.forID("Pacific/Chatham"))));
}

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

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

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

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

                    return list;
                }

            }, new StringConverter<Project>() {

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

                @Override
                public Project 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<Project>>() {

        @Override
        public void handle(AutoCompletionBinding.AutoCompletionEvent<Project> event) {
            Project project = event.getCompletion();
            //fill other item related fields

            PROJECT.setText(splitName(name.getText()));

            //populateAuditValues(client);
        }
    });
    // TODO
}

From source file:com.vmware.photon.controller.nsxclient.apis.LogicalSwitchApi.java

/**
 * Gets the state of a logical switch.//from w  ww  .ja  v  a 2s  . c o m
 */
public void getLogicalSwitchState(String id, FutureCallback<LogicalSwitchState> responseCallback)
        throws IOException {
    getAsync(LOGICAL_SWITCHS_BASE_PATH + "/" + id + "/state", HttpStatus.SC_OK,
            new TypeReference<LogicalSwitchState>() {
            }, responseCallback);
}