Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode toString.

Prototype

public String toString() 

Source Link

Usage

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java

@Test
public void testNoTypeSupplied() throws Exception {
    this.expectedException.expect(MessageConversionException.class);
    this.expectedException.expectMessage("does not contain a Type attribute");
    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();
    new NotificationRequestConverter().fromMessage(MessageBuilder.withPayload(payload).build(), null);
}

From source file:org.envirocar.aggregation.AggregatedTracksServlet.java

private String createTrackExists(String trackId) throws SQLException {
    ResultSet rs = this.connection.executeQueryStatement(String.format(trackQuery, trackId));

    ObjectNode result = om.createObjectNode();

    result.put("aggregated", rs.next());

    rs.close();/*  w ww .jav a  2s .c o m*/

    return result.toString();
}

From source file:azkaban.crypto.CryptoV1_1.java

@Override
public String encrypt(String plaintext, String passphrase, Version cryptoVersion) {
    Preconditions.checkArgument(Version.V1_1.equals(cryptoVersion));

    String cipheredText = newEncryptor(passphrase).encrypt(plaintext);
    ObjectNode node = MAPPER.createObjectNode();
    node.put(CIPHERED_TEXT_KEY, cipheredText);
    node.put(ICrypto.VERSION_IDENTIFIER, Version.V1_1.versionStr());

    return Crypto.encode(node.toString());
}

From source file:org.onosproject.restconf.ctl.web.RestconfResource.java

/**
 * Query RESTConf devices//from   w  ww .  j a va2 s  . c o m
 *
 * @return IP Address map
 */
@GET
@Path("list")
@Produces(MediaType.APPLICATION_JSON)
public Response deviceGetNotification() {

    log.info("Received Device list request");

    //RESTManager restService = get(RESTManager.class);
    // TODO Get a list of devices
    //List<RestconfDeviceEntry> list = restService.getAccessPoints();
    ObjectNode result = new ObjectMapper().createObjectNode();
    //result.set("list", new ESTConfDeviceCodec().encode(list, this));

    return ok(result.toString()).build();
}

From source file:com.sample.citybikesnyc.BikeStationDeserializer.java

@Override
public Object deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    final BikeStation bikeStation = new BikeStation();
    final JsonNode rootNode = jp.getCodec().readTree(jp);
    final String stationName = rootNode.get("stationName").textValue();
    bikeStation.setStationName(stationName);
    final int availableDocks = (Integer) (rootNode.get("availableDocks")).numberValue();
    bikeStation.setAvailableDocks(availableDocks);
    final int status = (Integer) (rootNode.get("status")).numberValue();
    bikeStation.setStatus(BikeStationStatus.valueOf(status));

    final ObjectNode locationNode = (ObjectNode) rootNode.get("location");
    final JavaType locationType = ctxt.constructType(Location.class);
    final JsonParser locationNodeParser = jp.getCodec().getFactory().createParser(locationNode.toString());

    final Location locationValue = (Location) ctxt.findNonContextualValueDeserializer(locationType)
            .deserialize(locationNodeParser, ctxt);
    bikeStation.setLocation(locationValue);
    return bikeStation;
}

From source file:dk.dbc.rawrepo.oai.ResumptionTokenTest.java

@Test
public void testEncryptDecrypt() throws Exception {
    ObjectNode jsonOriginal = (ObjectNode) new ObjectMapper().readTree("{\"foo\":\"bar\"}");

    String token = ResumptionToken.encode(jsonOriginal, 1);
    assertNotEquals(jsonOriginal.toString(), token);

    ObjectNode json = ResumptionToken.decode(token);
    assertEquals(jsonOriginal.toString(), json.toString());
}

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java

@Test
public void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception {
    // Arrange//from   www  .  java2  s  .  c  o m
    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Message", "World");
    String payload = jsonObject.toString();

    // Act
    Object notificationRequest = new NotificationRequestConverter()
            .fromMessage(MessageBuilder.withPayload(payload).build(), null);

    // Assert
    assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest));
    assertEquals("World",
            ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage());
}

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java

@Test
public void testWrongTypeSupplied() throws Exception {
    this.expectedException.expect(MessageConversionException.class);
    this.expectedException.expectMessage("is not a valid notification");
    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Subscription");
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();
    new NotificationRequestConverter().fromMessage(MessageBuilder.withPayload(payload).build(), null);
}

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java

@Test
public void testNoMessageAvailableSupplied() throws Exception {
    this.expectedException.expect(MessageConversionException.class);
    this.expectedException.expectMessage("does not contain a message");
    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "Hello World!");
    String payload = jsonObject.toString();
    new NotificationRequestConverter().fromMessage(MessageBuilder.withPayload(payload).build(), null);
}

From source file:org.springframework.cloud.aws.messaging.support.NotificationMessageArgumentResolverTest.java

@Test
public void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage() throws Exception {
    // Arrange/*from  w  ww . j a  v a2s .  c  o  m*/
    NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver();
    Method methodWithNotificationMessageArgument = this.getClass()
            .getDeclaredMethod("methodWithNotificationMessageArgument", String.class);
    MethodParameter methodParameter = new MethodParameter(methodWithNotificationMessageArgument, 0);

    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();
    Message<String> message = MessageBuilder.withPayload(payload).build();

    // Act
    Object result = notificationMessageArgumentResolver.resolveArgument(methodParameter, message);

    // Assert
    assertTrue(String.class.isInstance(result));
    assertEquals("Hello World!", result);
}