//package com.eactive.eai.transformer.message;
//
//import com.fasterxml.jackson.core.JsonGenerator;
//import com.fasterxml.jackson.core.JsonParser;
//import com.fasterxml.jackson.databind.DeserializationFeature;
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.node.JsonNodeFactory;
//import com.fasterxml.jackson.databind.node.ObjectNode;
//
//
//public class UJSONMessage extends JSONMessage {
//	private static final long serialVersionUID = -4490794379709362079L;
//	
//	public static final String MESSAGE_NAME = "UJSONMessage";
//	public static final String NAME = "UJSON";
//    public static String encode  = "UTF-8";
//
//    public UJSONMessage() {
//        super();
//        mapper = new ObjectMapper();
//        // if necessary, add proper options -> use system property config ?
////		mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
//        mapper = mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
//				.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
//				.setNodeFactory(JsonNodeFactory.withExactBigDecimals(true));
//		factory = mapper.getFactory();
//    }
//    
//    @Override
//	protected void doSetData(Object data, boolean refCountLimit) {
//		JsonParser parser = null; 
//		String jsonString = null;
//		try {
//			if (data instanceof String) {
//				jsonString = (String) data;
//				parser = factory.createParser(jsonString);
//				this.data = mapper.readTree(parser);				
//			} else if (data instanceof byte[]) {				
//				jsonString = new String((byte[]) data,encode);
//				parser = factory.createParser(jsonString);
//				this.data = mapper.readTree(parser);				
//	        } else if (data instanceof JsonNode) {
//	        	this.data = (JsonNode) data;
//	        } else {
//	            if (data == null) {
//	                throw new InvalidDataTypeException("Not able to generate JSON messages with data. Input value is null.", data);
//	            
//	            } else {
//	                throw new InvalidDataTypeException("Not able to generate JSON messages with data. data type = " + data.getClass().getName(), data);
//	            }
//	        }
//			
//			ObjectNode node = (ObjectNode) this.data.get(getName());
//			if(node == null) {
//				// if  layoutname not appended
//				setValue(this.data, getName());
//			}
//			else {
//				setValue(node, getName());
//			}
//	    } catch (Exception e) {
//	        throw new MessageSetDataException(e.getMessage(), this, data, e);
//	    }
//	}
//	  
//	@Override
//	public void copy(Message message) throws Exception {
//		try {
//	        this.data =  ((UJSONMessage)message).getJSONObject();
//	    } catch (Exception e) {
//	    	logger.error(e.getMessage(),e);
//	        throw new InvalidMessageException(e.getMessage(), message, e);
//	    }
//	}
//	
//	private String getHeader() {
//    	return getName() + " (" + MESSAGE_NAME + ") encoding="+encode;
//    }
//    
//    public String toString() {
//        StringBuffer sb = new StringBuffer();
//        sb.append(getHeader());;
//        sb.append(super.toBodyString());
//        return sb.toString();
//    }	
//}
