@Override
    public AckArgs deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
      List<Object> args = new ArrayList<Object>();
      AckArgs result = new AckArgs(args);

      ObjectMapper mapper = (ObjectMapper) jp.getCodec();
      JsonNode root = mapper.readTree(jp);
      AckCallback<?> callback = currentAckClass.get();
      Iterator<JsonNode> iter = root.iterator();
      int i = 0;
      while (iter.hasNext()) {
        Object val;

        Class<?> clazz = callback.getResultClass();
        if (callback instanceof MultiTypeAckCallback) {
          MultiTypeAckCallback multiTypeAckCallback = (MultiTypeAckCallback) callback;
          clazz = multiTypeAckCallback.getResultClasses()[i];
        }

        JsonNode arg = iter.next();
        if (arg.isTextual() || arg.isBoolean()) {
          clazz = Object.class;
        }

        val = mapper.treeToValue(arg, clazz);
        args.add(val);
        i++;
      }
      return result;
    }
Esempio n. 2
0
 @Override
 public LatLng deserialize(JsonParser jp, DeserializationContext _any) throws IOException {
   TreeNode node = jp.getCodec().readTree(jp);
   double lat = ((NumericNode) node.get(0)).doubleValue();
   double lng = ((NumericNode) node.get(1)).doubleValue();
   return new LatLng(lat, lng);
 }
    @Override
    public Event deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
      ObjectMapper mapper = (ObjectMapper) jp.getCodec();
      String eventName = jp.nextTextValue();

      EventKey ek = new EventKey(namespaceClass.get(), eventName);
      if (!eventMapping.containsKey(ek)) {
        ek = new EventKey(Namespace.DEFAULT_NAME, eventName);
        if (!eventMapping.containsKey(ek)) {
          return new Event(eventName, Collections.emptyList());
        }
      }

      List<Object> eventArgs = new ArrayList<Object>();
      Event event = new Event(eventName, eventArgs);
      List<Class<?>> eventClasses = eventMapping.get(ek);
      int i = 0;
      while (true) {
        JsonToken token = jp.nextToken();
        if (token == JsonToken.END_ARRAY) {
          break;
        }
        if (i > eventClasses.size() - 1) {
          log.debug("Event {} has more args than declared in handler: {}", eventName, null);
          break;
        }
        Class<?> eventClass = eventClasses.get(i);
        Object arg = mapper.readValue(jp, eventClass);
        eventArgs.add(arg);
        i++;
      }
      return event;
    }
 @Override
 public Member deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   JsonNode node = jp.getCodec().readTree(jp);
   String key = node.get("key").textValue();
   Member result = memberRepository.findOneByKey(key);
   return result;
 }
 @Override
 public Rectangle2D deserialize(
     final JsonParser parser, final DeserializationContext context)
     throws IOException, JsonProcessingException {
   final JsonNode tree = parser.getCodec().readTree(parser);
   return new Rectangle2D.Double(
       tree.get("X").asDouble(),
       tree.get("Y").asDouble(),
       tree.get("Width").asDouble(),
       tree.get("Height").asDouble());
 }
 protected ReturnType parseReturnType(final JsonParser jp, final String elementName)
     throws IOException {
   ReturnType returnType;
   if (elementName.equals(((FromXmlParser) jp).getStaxReader().getLocalName())) {
     returnType = new ReturnType();
     returnType.setType(jp.nextTextValue());
   } else {
     jp.nextToken();
     returnType = jp.getCodec().readValue(jp, ReturnType.class);
   }
   return returnType;
 }
 @Override
 public Cookie deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   ObjectMapper mapper = (ObjectMapper) jp.getCodec();
   JsonNode jsonNode = mapper.readTree(jp);
   Cookie cookie =
       new Cookie(
           readJsonNode(jsonNode, "name").asText(), readJsonNode(jsonNode, "value").asText());
   cookie.setComment(readJsonNode(jsonNode, "comment").asText());
   cookie.setDomain(readJsonNode(jsonNode, "domain").asText());
   cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
   cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
   cookie.setVersion(readJsonNode(jsonNode, "version").asInt());
   cookie.setPath(readJsonNode(jsonNode, "path").asText());
   cookie.setHttpOnly(readJsonNode(jsonNode, "httpOnly").asBoolean());
   return cookie;
 }
Esempio n. 8
0
    @Override
    public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

      List<Volume> volumes = new ArrayList<Volume>();
      ObjectCodec oc = jsonParser.getCodec();
      JsonNode node = oc.readTree(jsonParser);
      for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext(); ) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
          String path = field.getKey();
          Volume volume = new Volume(path);
          volumes.add(volume);
        }
      }
      return new Volumes(volumes.toArray(new Volume[0]));
    }
  @Override
  protected ReferentialConstraintRole doDeserialize(
      final JsonParser jp, final DeserializationContext ctxt)
      throws IOException, JsonProcessingException {

    final ReferentialConstraintRole refConstRole = new ReferentialConstraintRole();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
      final JsonToken token = jp.getCurrentToken();
      if (token == JsonToken.FIELD_NAME) {
        if ("Role".equals(jp.getCurrentName())) {
          refConstRole.setRole(jp.nextTextValue());
        } else if ("PropertyRef".equals(jp.getCurrentName())) {
          jp.nextToken();
          refConstRole.getPropertyRefs().add(jp.getCodec().readValue(jp, PropertyRef.class));
        }
      }
    }

    return refConstRole;
  }
  @Override
  public Policy deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    Policy policy = new Policy();
    node.fieldNames()
        .forEachRemaining(
            field -> {
              JsonNode subNode = node.findValue(field);
              policy.setName(field);
              policy.setConfiguration(subNode.toString());

              System.out.println(field);
            });

    /*
    policy.setName(node.get("policy").asText());
    policy.setConfiguration(node.getget("configuration").toString());
    */

    return policy;
  }
  // TODO - See 'Can't create HyperLogLogPlus sketches in JSON'
  @Override
  public HyperLogLogPlus deserialize(
      final JsonParser jsonParser, final DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {

    final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);

    final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus");
    if (coreHyperLogLogPlusObject != null) {
      final TextNode jsonNodes =
          (TextNode)
              coreHyperLogLogPlusObject.get(
                  HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);

      final byte[] nodeAsString = jsonNodes.binaryValue();
      final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString);

      return hyperLogLogPlus;
    } else {
      throw new IllegalArgumentException("Recieved null or empty HyperLogLogPlus sketch");
    }
  }
  @Override
  public TroubleReportTemplate deserialize(
      JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
    JsonNode troubleReportTemplate = jsonNode.get("troubleReportTemplate");

    ServiceProblemId serviceProblemId =
        new ServiceProblemId(troubleReportTemplate.get("serviceProblemId").asLong());
    String troubleReportId = troubleReportTemplate.get("troubleReportId").asText();
    String appointmentReference = troubleReportTemplate.get("appointmentReference").asText();
    boolean twentyFourHourAccess = troubleReportTemplate.get("twentyFourHourAccess").asBoolean();
    String earliestAccessDate =
        troubleReportTemplate.get("earliestAccessDate").asText().equals("null")
            ? null
            : troubleReportTemplate.get("earliestAccessDate").asText();
    String latestAccessDate =
        troubleReportTemplate.get("latestAccessDate").asText().equals("null")
            ? null
            : troubleReportTemplate.get("latestAccessDate").asText();
    String serviceTypeCode = troubleReportTemplate.get("serviceType").get("code").asText();
    SnsServiceId serviceId = new SnsServiceId(troubleReportTemplate.get("serviceId").asLong());
    String providerReference = troubleReportTemplate.get("providerReference").asText();
    String btReference = troubleReportTemplate.get("btReference").asText();
    String description = troubleReportTemplate.get("description").asText();
    String accessHazards = troubleReportTemplate.get("accessHazards").asText();
    String accessNotes = troubleReportTemplate.get("accessNotes").asText();
    String contactName = troubleReportTemplate.get("contactName").asText();
    String contactNumber = troubleReportTemplate.get("contactNumber").asText();
    String secondaryContactName = troubleReportTemplate.get("secondaryContactName").asText();
    String secondaryContactNumber = troubleReportTemplate.get("secondaryContactNumber").asText();
    String notes = troubleReportTemplate.get("notes").asText();
    String temporaryCallDiversionNumber =
        troubleReportTemplate.get("temporaryCallDiversionNumber").asText();
    int upperTrcBand = troubleReportTemplate.get("upperTrcBand").asInt();
    boolean cancelRequested = troubleReportTemplate.get("cancelRequested").asBoolean();
    boolean amendRequested = troubleReportTemplate.get("amendRequested").asBoolean();
    boolean confirmEquipmentDisconnectedRequested =
        troubleReportTemplate.get("confirmEquipmentDisconnectedRequested").asBoolean();
    boolean broadbandFault = troubleReportTemplate.get("broadbandFault").asBoolean();
    boolean coopCallRequested = troubleReportTemplate.get("coopCallRequested").asBoolean();
    boolean disRequested = troubleReportTemplate.get("disRequested").asBoolean();
    boolean isResponseRequired = troubleReportTemplate.get("isResponseRequired").asBoolean();
    boolean intermittentProblem = troubleReportTemplate.get("intermittentProblem").asBoolean();
    JsonNode symptomNode = troubleReportTemplate.get("symptom");
    TroubleReportSymptomDTO symptom =
        new TroubleReportSymptomDTO(
            symptomNode.get("symptomCode").asText(),
            symptomNode.get("providerCode").asText(),
            symptomNode.get("description").asText(),
            symptomNode.get("mapsToNetworkFeature").asBoolean(),
            symptomNode.get("mapToNetworkFeatureName").asText(),
            symptomNode.get("mapToNetworkFeaturePin").asText());
    JsonNode lineTestSummaryNode = troubleReportTemplate.get("lineTestSummary");
    LineTestSummaryDTO lineTestSummary =
        new LineTestSummaryDTO(
            lineTestSummaryNode.get("lineTestReference").asText(),
            lineTestSummaryNode.get("performerReference").asText(),
            lineTestSummaryNode.get("mainFaultLocation").asText(),
            lineTestSummaryNode.get("isCompleted").asBoolean(),
            lineTestSummaryNode.get("faultReportAdvised").asBoolean(),
            lineTestSummaryNode.get("requiresAppointment").asBoolean());

    StructuredQuestionCode structuredQuestionCode = null;
    if (troubleReportTemplate.hasNonNull("structuredQuestionCode")) {
      structuredQuestionCode =
          StructuredQuestionCode.valueOf(
              troubleReportTemplate.get("structuredQuestionCode").asText());
    }

    TroubleReportStatus troubleReportStatus = TroubleReportStatus.New;
    if (troubleReportTemplate.hasNonNull("status")) {
      troubleReportStatus =
          TroubleReportStatus.valueOf(troubleReportTemplate.get("status").asText());
    }

    TestProduct testProduct = null;
    if (troubleReportTemplate.hasNonNull("testProduct")) {
      testProduct = TestProduct.valueOf(troubleReportTemplate.get("testProduct").asText());
    }

    return new TroubleReportTemplateBuilder()
        .with(serviceProblemId)
        .withTwentyFourHourAccess(twentyFourHourAccess)
        .withEarliestAccessDate(new Date())
        .withAppointmentReference(appointmentReference)
        .withEarliestAccessDate(
            earliestAccessDate != null
                ? Date.from(ZonedDateTime.parse(earliestAccessDate).toInstant())
                : null)
        .withLatestAccessDate(
            latestAccessDate != null
                ? Date.from(ZonedDateTime.parse(latestAccessDate).toInstant())
                : null)
        .withServiceType(ServiceType.valueOf(serviceTypeCode))
        .with(serviceId)
        .withProviderReference(providerReference)
        .withBtReference(btReference)
        .withDescription(description)
        .withAccessHazards(accessHazards)
        .withAccessNotes(accessNotes)
        .withContactName(contactName)
        .withContactNumber(contactNumber)
        .withSecondaryContactName(secondaryContactName)
        .withSecondaryContactNumber(secondaryContactNumber)
        .withNotes(notes)
        .withTemporaryCallDiversionNumber(temporaryCallDiversionNumber)
        .withCancelRequested(cancelRequested)
        .withAmendRequested(amendRequested)
        .withConfirmEquipmentDisconnectedRequested(confirmEquipmentDisconnectedRequested)
        .withBroadbandFault(broadbandFault)
        .withCoopCallRequested(coopCallRequested)
        .withDisRequested(disRequested)
        .withIsResponseRequired(isResponseRequired)
        .withIntermittentProblem(intermittentProblem)
        .withSymptom(symptom)
        .withLineTestSummary(lineTestSummary)
        .withUpperTrcBand(troubleReportTemplate.get("upperTrcBand").asInt())
        .withTestProduct(testProduct)
        .withStructuredQuestionCode(structuredQuestionCode)
        .withStatus(troubleReportStatus)
        .withTroubleReportId(new TroubleReportId(troubleReportId))
        .withUpperTrcBand(upperTrcBand)
        .build();
  }
 @Override
 public Point deserialize(final JsonParser parser, final DeserializationContext context)
     throws IOException, JsonProcessingException {
   final JsonNode tree = parser.getCodec().readTree(parser);
   return new Point(tree.get("X").asInt(), tree.get("Y").asInt());
 }
  @Override
  public ActionItem deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    ObjectNode objectNode = jp.readValueAsTree();
    JsonNode wrapped = objectNode.get("actionItemType");
    JsonParser parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    ActionItemType actionItemType = parser.readValueAs(ActionItemType.class);

    wrapped = objectNode.get("actionItemId");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    Long actionItemId = parser.getValueAsLong();

    wrapped = objectNode.get("actionItemCreateDate");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    Date actionItemCreateDate = new Date(parser.getValueAsLong());

    wrapped = objectNode.get("actionItemName");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    String actionItemName = parser.getValueAsString();

    wrapped = objectNode.get("actionItemDueDate");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    Date actionItemDueDate = new Date(parser.getValueAsLong());

    wrapped = objectNode.get("discussionId");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    Long discussionId = parser.getValueAsLong();

    wrapped = objectNode.get("owner");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    MmrActionItemUser owner = parser.readValueAs(MmrActionItemUser.class);

    wrapped = objectNode.get("assignees");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    List<MmrActionItemUser> assignees =
        parser.readValueAs(new TypeReference<List<MmrActionItemUser>>() {});

    wrapped = objectNode.get("actionItemStatus");
    parser = wrapped.traverse();
    parser.setCodec(jp.getCodec());
    ActionItemStatus actionItemStatus = parser.readValueAs(ActionItemStatus.class);

    ActionItem actionItem = new UntypedActionItem();
    actionItem.setActionItemType(actionItemType);
    actionItem.setActionItemId(actionItemId);
    actionItem.setActionItemStatus(actionItemStatus);
    actionItem.setAssignees(assignees);
    actionItem.setActionItemCreateDate(actionItemCreateDate);
    actionItem.setActionItemDueDate(actionItemDueDate);
    actionItem.setActionItemName(actionItemName);
    actionItem.setDiscussionId(discussionId);
    actionItem.setOwner(owner);

    return actionItem;
  }
  @Override
  public CLAClassifier deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {

    ObjectCodec oc = jp.getCodec();
    JsonNode node = oc.readTree(jp);

    CLAClassifier retVal = new CLAClassifier();
    retVal.alpha = node.get("alpha").asDouble();
    retVal.actValueAlpha = node.get("actValueAlpha").asDouble();
    retVal.learnIteration = node.get("learnIteration").asInt();
    retVal.recordNumMinusLearnIteration = node.get("recordNumMinusLearnIteration").asInt();
    retVal.maxBucketIdx = node.get("maxBucketIdx").asInt();

    String[] steps = node.get("steps").asText().split(",");
    TIntList t = new TIntArrayList();
    for (String step : steps) {
      t.add(Integer.parseInt(step));
    }
    retVal.steps = t;

    String[] tupleStrs = node.get("patternNZHistory").asText().split(";");
    Deque<Tuple> patterns = new Deque<Tuple>(tupleStrs.length);
    for (String tupleStr : tupleStrs) {
      String[] tupleParts = tupleStr.split("-");
      int iteration = Integer.parseInt(tupleParts[0]);
      String pattern = tupleParts[1].substring(1, tupleParts[1].indexOf("]")).trim();
      String[] indexes = pattern.split(",");
      int[] indices = new int[indexes.length];
      for (int i = 0; i < indices.length; i++) {
        indices[i] = Integer.parseInt(indexes[i].trim());
      }
      Tuple tup = new Tuple(iteration, indices);
      patterns.append(tup);
    }
    retVal.patternNZHistory = patterns;

    Map<Tuple, BitHistory> bitHistoryMap = new HashMap<Tuple, BitHistory>();
    String[] bithists = node.get("activeBitHistory").asText().split(";");
    for (String bh : bithists) {
      String[] parts = bh.split("-");

      String[] left = parts[0].split(",");
      Tuple iteration =
          new Tuple(Integer.parseInt(left[0].trim()), Integer.parseInt(left[1].trim()));

      BitHistory bitHistory = new BitHistory();
      String[] right = parts[1].split("=");
      bitHistory.id = right[0].trim();

      TDoubleList dubs = new TDoubleArrayList();
      String[] stats = right[1].substring(1, right[1].indexOf("}")).trim().split(",");
      for (int i = 0; i < stats.length; i++) {
        dubs.add(Double.parseDouble(stats[i].trim()));
      }
      bitHistory.stats = dubs;

      bitHistory.lastTotalUpdate = Integer.parseInt(right[2].trim());

      bitHistoryMap.put(iteration, bitHistory);
    }
    retVal.activeBitHistory = bitHistoryMap;

    ArrayNode jn = (ArrayNode) node.get("actualValues");
    List<Object> l = new ArrayList<Object>();
    for (int i = 0; i < jn.size(); i++) {
      JsonNode n = jn.get(i);
      try {
        double d = Double.parseDouble(n.asText().trim());
        l.add(d);
      } catch (Exception e) {
        l.add(n.asText().trim());
      }
    }
    retVal.actualValues = l;

    // Go back and set the classifier on the BitHistory objects
    for (Tuple tuple : bitHistoryMap.keySet()) {
      bitHistoryMap.get(tuple).classifier = retVal;
    }

    return retVal;
  }
  @Override
  public ServerConfigData deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException {
    ObjectCodec codec = jp.getCodec();
    ObjectNode serverNode = jp.readValueAsTree();
    ServerConfigData data =
        new ServerConfigData(baseDirSupplier.get(), address, port, development, publicAddress);
    if (serverNode.hasNonNull("port")) {
      data.setPort(parsePort(serverNode.get("port")));
    }
    if (serverNode.hasNonNull("address")) {
      data.setAddress(toValue(codec, serverNode.get("address"), InetAddress.class));
    }
    if (serverNode.hasNonNull("development")) {
      data.setDevelopment(serverNode.get("development").asBoolean(false));
    }
    if (serverNode.hasNonNull("threads")) {
      data.setThreads(serverNode.get("threads").asInt(ServerConfig.DEFAULT_THREADS));
    }
    if (serverNode.hasNonNull("publicAddress")) {
      data.setPublicAddress(toValue(codec, serverNode.get("publicAddress"), URI.class));
    }
    if (serverNode.hasNonNull("maxContentLength")) {
      data.setMaxContentLength(
          serverNode.get("maxContentLength").asInt(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH));
    }
    if (serverNode.hasNonNull("maxChunkSize")) {
      data.setMaxChunkSize(
          serverNode.get("maxChunkSize").asInt(ServerConfig.DEFAULT_MAX_CHUNK_SIZE));
    }
    if (serverNode.hasNonNull("maxInitialLineLength")) {
      data.setMaxInitialLineLength(
          serverNode
              .get("maxInitialLineLength")
              .asInt(ServerConfig.DEFAULT_MAX_INITIAL_LINE_LENGTH));
    }
    if (serverNode.hasNonNull("maxHeaderSize")) {
      data.setMaxHeaderSize(
          serverNode.get("maxHeaderSize").asInt(ServerConfig.DEFAULT_MAX_HEADER_SIZE));
    }
    if (serverNode.hasNonNull("ssl")) {
      data.setSslContext(toValue(codec, serverNode.get("ssl"), SSLContext.class));
    }
    if (serverNode.hasNonNull("requireClientSslAuth")) {
      data.setRequireClientSslAuth(serverNode.get("requireClientSslAuth").asBoolean(false));
    }
    if (serverNode.hasNonNull("baseDir")) {
      throw new IllegalStateException(
          "baseDir value cannot be set via config, it must be set directly via ServerConfigBuilder.baseDir()");
    }
    if (serverNode.hasNonNull("connectTimeoutMillis")) {
      parseOptionalIntValue("connectTimeoutMillis", serverNode.get("connectTimeoutMillis"))
          .ifPresent(data::setConnectTimeoutMillis);
    }
    if (serverNode.hasNonNull("maxMessagesPerRead")) {
      parseOptionalIntValue("maxMessagesPerRead", serverNode.get("maxMessagesPerRead"))
          .ifPresent(data::setMaxMessagesPerRead);
    }
    if (serverNode.hasNonNull("receiveBufferSize")) {
      parseOptionalIntValue("receiveBufferSize", serverNode.get("receiveBufferSize"))
          .ifPresent(data::setReceiveBufferSize);
    }
    if (serverNode.hasNonNull("writeSpinCount")) {
      parseOptionalIntValue("writeSpinCount", serverNode.get("writeSpinCount"))
          .ifPresent(data::setWriteSpinCount);
    }

    return data;
  }