001/*
002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved.
003 *
004 * Project and contact information: http://www.cascading.org/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.nested.json;
022
023import java.beans.ConstructorProperties;
024import java.util.Collections;
025import java.util.Map;
026
027import cascading.nested.core.NestedSetFunction;
028import cascading.tuple.Fields;
029import com.fasterxml.jackson.databind.JsonNode;
030import com.fasterxml.jackson.databind.node.ArrayNode;
031
032/**
033 * Class JSONSetFunction provides for the ability to simply set multiple tuple values onto an existing JSON object.
034 *
035 * @see NestedSetFunction for more details.
036 */
037public class JSONSetFunction extends NestedSetFunction<JsonNode, ArrayNode>
038  {
039  /**
040   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
041   * an existing JSON object, where all the JSON object attributes are the argument field names.
042   *
043   * @param fieldDeclaration of Fields
044   */
045  @ConstructorProperties({"fieldDeclaration"})
046  public JSONSetFunction( Fields fieldDeclaration )
047    {
048    super( JSONCoercibleType.TYPE, fieldDeclaration );
049    }
050
051  /**
052   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
053   * an existing JSON object, where all the JSON object attributes are the argument field names.
054   * <p>
055   * The {@code rootPointer} values specifies the base name of the final pointer path. If {@code rootPointer} is
056   * "/person" and and argument is passed with field name "fullName", the value will be placed in "/person/fullName".
057   *
058   * @param fieldDeclaration of Fields
059   * @param rootPointer      of String
060   */
061  @ConstructorProperties({"fieldDeclaration", "rootPointer"})
062  public JSONSetFunction( Fields fieldDeclaration, String rootPointer )
063    {
064    super( JSONCoercibleType.TYPE, fieldDeclaration, rootPointer );
065    }
066
067  /**
068   * Creates a new JSONSetFunction instance.
069   *
070   * @param fieldDeclaration of Fields
071   * @param fromFields       of Fields
072   * @param stringPointer    of String
073   */
074  public JSONSetFunction( Fields fieldDeclaration, Fields fromFields, String stringPointer )
075    {
076    this( fieldDeclaration, Collections.singletonMap( fromFields, stringPointer ) );
077    }
078
079  /**
080   * Creates a new JSONSetFunction instance.
081   *
082   * @param fieldDeclaration of Fields
083   * @param pointerMap       of Map
084   */
085  public JSONSetFunction( Fields fieldDeclaration, Map<Fields, String> pointerMap )
086    {
087    super( JSONCoercibleType.TYPE, fieldDeclaration, pointerMap );
088    }
089  }