Coverage Report - org.mule.module.json.JsonNodeExpressionEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonNodeExpressionEvaluator
0%
0/12
0%
0/6
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.json;
 8  
 
 9  
 import org.mule.routing.AbstractSplitter;
 10  
 
 11  
 import java.util.ArrayList;
 12  
 import java.util.Iterator;
 13  
 import java.util.List;
 14  
 
 15  
 import org.codehaus.jackson.JsonNode;
 16  
 import org.codehaus.jackson.node.ArrayNode;
 17  
 import org.codehaus.jackson.node.ValueNode;
 18  
 
 19  
 /**
 20  
  * An JSON expression evaluator that returns {@link JsonNode}'s instead of strings.
 21  
  * Arrays are still returned as a {@link List} rather than as an {@link ArrayNode} to
 22  
  * enable splitting using the {@link AbstractSplitter}
 23  
  * 
 24  
  * @see org.mule.module.json.JsonData
 25  
  * @see JsonExpressionEvaluator
 26  
  */
 27  0
 public class JsonNodeExpressionEvaluator extends JsonExpressionEvaluator
 28  
 {
 29  
 
 30  
     protected Object extractResultFromNode(JsonNode result)
 31  
     {
 32  0
         if (result instanceof ValueNode)
 33  
         {
 34  0
             return result.getValueAsText();
 35  
         }
 36  0
         if (result instanceof ArrayNode)
 37  
         {
 38  0
             List parts = new ArrayList<String>();
 39  0
             for (Iterator<JsonNode> i = ((JsonNode) result).getElements(); i.hasNext();)
 40  
             {
 41  0
                 JsonNode arrayNode = i.next();
 42  0
                 parts.add(extractResultFromNode(arrayNode));
 43  0
             }
 44  0
             return parts;
 45  
         }
 46  
         else
 47  
         {
 48  0
             return result;
 49  
         }
 50  
     }
 51  
 
 52  
     public String getName()
 53  
     {
 54  0
         return "json-node";
 55  
     }
 56  
 }