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

ru.cwcode.tkach.config.jackson.module.MessageDeserializer 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.Message;

import java.io.IOException;

public class MessageDeserializer extends JsonDeserializer {
  @Override
  public Message deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = p.getCodec();
    JsonNode node = codec.readTree(p);
    
    if (node.has("message")) {
      return new Message(node.get("message").asText());
    }
    
    return new Message(node.asText());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy