001/* 002 * Copyright (c) 2007-2022 The Cascading Authors. All Rights Reserved. 003 * 004 * Project and contact information: https://cascading.wensel.net/ 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.Map; 025 026import cascading.nested.core.NestedGetAllFunction; 027import cascading.tuple.Fields; 028import com.fasterxml.jackson.databind.JsonNode; 029import com.fasterxml.jackson.databind.node.ArrayNode; 030 031/** 032 * Class JSONGetAllFunction provides the ability to retrieve a list of child nodes and 033 * convert each JSON object into tuple of values. 034 * 035 * Note the {@code stringRootPointer} may reference a JSON Array, {@code /person/*}, or it may be a pointer-path 036 * descent reference, {@code /person/**}{@code /name}. In the later case, use an empty pointer, {@code ""}, to reference 037 * the value of the array. Rely on the {@code fieldDeclaration} to coerce this value appropriately. 038 * 039 * @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a> 040 * @see NestedGetAllFunction for more details. 041 */ 042public class JSONGetAllFunction extends NestedGetAllFunction<JsonNode, ArrayNode> 043 { 044 /** 045 * Creates a new JSONGetAllFunction instance. 046 * 047 * @param stringRootPointer of String 048 * @param pointerMap of Map 049 */ 050 @ConstructorProperties({"stringRootPointer", "pointerMap"}) 051 public JSONGetAllFunction( String stringRootPointer, Map<Fields, String> pointerMap ) 052 { 053 this( stringRootPointer, asFields( pointerMap.keySet() ), asArray( pointerMap.values() ) ); 054 } 055 056 /** 057 * Creates a new JSONGetAllFunction instance. 058 * 059 * @param stringRootPointer of String 060 * @param pointerMap of Map 061 * @param failOnMissingNode of boolean 062 */ 063 @ConstructorProperties({"stringRootPointer", "pointerMap", "failOnMissingNode"}) 064 public JSONGetAllFunction( String stringRootPointer, Map<Fields, String> pointerMap, boolean failOnMissingNode ) 065 { 066 this( stringRootPointer, asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); 067 } 068 069 /** 070 * Creates a new JSONGetAllFunction instance. 071 * 072 * @param stringRootPointer of String 073 * @param fieldDeclaration of Fields 074 * @param stringPointers of String... 075 */ 076 @ConstructorProperties({"stringRootPointer", "fieldDeclaration", "stringPointers"}) 077 public JSONGetAllFunction( String stringRootPointer, Fields fieldDeclaration, String... stringPointers ) 078 { 079 this( stringRootPointer, fieldDeclaration, false, stringPointers ); 080 } 081 082 /** 083 * Creates a new JSONGetAllFunction instance. 084 * 085 * @param stringRootPointer of String 086 * @param fieldDeclaration of Fields 087 * @param failOnMissingNode of boolean 088 * @param stringPointers of String... 089 */ 090 @ConstructorProperties({"stringRootPointer", "fieldDeclaration", "failOnMissingNode", "stringPointers"}) 091 public JSONGetAllFunction( String stringRootPointer, Fields fieldDeclaration, boolean failOnMissingNode, String... stringPointers ) 092 { 093 super( JSONCoercibleType.TYPE, stringRootPointer, fieldDeclaration, failOnMissingNode, stringPointers ); 094 } 095 096 /** 097 * Creates a new JSONGetAllFunction instance. 098 * 099 * @param coercibleType of JSONCoercibleType 100 * @param stringRootPointer of String 101 * @param pointerMap of Map 102 */ 103 @ConstructorProperties({"coercibleType", "stringRootPointer", "pointerMap"}) 104 public JSONGetAllFunction( JSONCoercibleType coercibleType, String stringRootPointer, Map<Fields, String> pointerMap ) 105 { 106 this( coercibleType, stringRootPointer, asFields( pointerMap.keySet() ), asArray( pointerMap.values() ) ); 107 } 108 109 /** 110 * Creates a new JSONGetAllFunction instance. 111 * 112 * @param coercibleType of JSONCoercibleType 113 * @param stringRootPointer of String 114 * @param pointerMap of Map 115 * @param failOnMissingNode of boolean 116 */ 117 @ConstructorProperties({"coercibleType", "stringRootPointer", "pointerMap", "failOnMissingNode"}) 118 public JSONGetAllFunction( JSONCoercibleType coercibleType, String stringRootPointer, Map<Fields, String> pointerMap, boolean failOnMissingNode ) 119 { 120 this( coercibleType, stringRootPointer, asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); 121 } 122 123 /** 124 * Creates a new JSONGetAllFunction instance. 125 * 126 * @param coercibleType of JSONCoercibleType 127 * @param stringRootPointer of String 128 * @param fieldDeclaration of Fields 129 * @param stringPointers of String... 130 */ 131 @ConstructorProperties({"coercibleType", "stringRootPointer", "fieldDeclaration", "stringPointers"}) 132 public JSONGetAllFunction( JSONCoercibleType coercibleType, String stringRootPointer, Fields fieldDeclaration, String... stringPointers ) 133 { 134 this( coercibleType, stringRootPointer, fieldDeclaration, false, stringPointers ); 135 } 136 137 /** 138 * Creates a new JSONGetAllFunction instance. 139 * 140 * @param coercibleType of JSONCoercibleType 141 * @param stringRootPointer of String 142 * @param fieldDeclaration of Fields 143 * @param failOnMissingNode of boolean 144 * @param stringPointers of String... 145 */ 146 @ConstructorProperties({"coercibleType", "stringRootPointer", "fieldDeclaration", "failOnMissingNode", 147 "stringPointers"}) 148 public JSONGetAllFunction( JSONCoercibleType coercibleType, String stringRootPointer, Fields fieldDeclaration, boolean failOnMissingNode, String... stringPointers ) 149 { 150 super( coercibleType, stringRootPointer, fieldDeclaration, failOnMissingNode, stringPointers ); 151 } 152 }