All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.cwcode.tkach.config.jackson.module.MessageArrDeserializer Maven / Gradle / Ivy

The newest version!
package ru.cwcode.tkach.config.jackson.module;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import ru.cwcode.tkach.locale.MessageArr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MessageArrDeserializer extends JsonDeserializer {
  @Override
  public MessageArr deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = p.getCodec();
    JsonNode node = codec.readTree(p);
    
    if (node.has("message")) {
      node = node.get("message");
    }
    
    List values = new ArrayList<>();
    
    for (JsonNode jsonNode : node) {
      values.add(jsonNode.asText());
    }
    
    return new MessageArr(values.toArray(new String[0]));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy