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.NestedCreateFunction; 028import cascading.tuple.Fields; 029import com.fasterxml.jackson.databind.JsonNode; 030import com.fasterxml.jackson.databind.node.ArrayNode; 031 032/** 033 * Class JSONCreateFunction provides for the ability to simply set multiple tuple values onto a new JSON object. 034 * 035 * @see NestedCreateFunction for more details. 036 */ 037public class JSONCreateFunction extends NestedCreateFunction<JsonNode, ArrayNode> 038 { 039 /** 040 * Creates a new JSONCreateFunction instance that will pivot all resolved arguments fields into 041 * a new 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 JSONCreateFunction( Fields fieldDeclaration ) 047 { 048 super( JSONCoercibleType.TYPE, fieldDeclaration ); 049 } 050 051 /** 052 * Creates a new JSONCreateFunction instance that will pivot all resolved arguments fields into 053 * a new 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 JSONCreateFunction( Fields fieldDeclaration, String rootPointer ) 063 { 064 super( JSONCoercibleType.TYPE, fieldDeclaration, rootPointer ); 065 } 066 067 /** 068 * Creates a new JSONCreateFunction instance that maps the given {@code fromFields} value to the location 069 * declared by the {@code stringPointer}. 070 * 071 * @param fieldDeclaration of Fields 072 * @param fromFields of Fields 073 * @param stringPointer of String 074 */ 075 @ConstructorProperties({"fieldDeclaration", "fromFields", "stringPointer"}) 076 public JSONCreateFunction( Fields fieldDeclaration, Fields fromFields, String stringPointer ) 077 { 078 this( fieldDeclaration, Collections.singletonMap( fromFields, stringPointer ) ); 079 } 080 081 /** 082 * Creates a new JSONCreateFunction instance that maps all the Fields declared in the 083 * {@code pointerMap} to the declared path pointers. 084 * 085 * @param fieldDeclaration of Fields 086 * @param pointerMap of Map 087 */ 088 @ConstructorProperties({"fieldDeclaration", "pointerMap"}) 089 public JSONCreateFunction( Fields fieldDeclaration, Map<Fields, String> pointerMap ) 090 { 091 super( JSONCoercibleType.TYPE, fieldDeclaration, pointerMap ); 092 } 093 }