package com.libreecm.commonAPI.auxiliars;

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

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.libreecm.commonAPI.model.CmisExtensionElement;

public class JsonCmisExtensionElementListDeserializer extends JsonDeserializer<ArrayList<CmisExtensionElement>> {
	
	
    @Override

    public ArrayList<CmisExtensionElement> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    	ArrayList<CmisExtensionElement> result = new ArrayList<CmisExtensionElement>();
    	
    	//The problem is when extensions=null
    	String input= jp.getText();
    	if (input.startsWith("[\""))
    		input=input.substring(2, input.length()-1);
    	if (input.endsWith("\"]"))
    		input=input.substring(0,input.length()-3);
    	
    	//now we have: HR","IT","SC
    	//if any element has char " it will be no problem because it will be \"
    	return result;
    }


}