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.NestedGetFunction; 027import cascading.tuple.Fields; 028import com.fasterxml.jackson.databind.JsonNode; 029import com.fasterxml.jackson.databind.node.ArrayNode; 030 031/** 032 * Class JSONGetFunction provides the ability to convert a JSON object into a single tuple where each 033 * field value is referenced by a Json pointer in the object. 034 * 035 * @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a> 036 * @see NestedGetFunction for more details. 037 */ 038public class JSONGetFunction extends NestedGetFunction<JsonNode, ArrayNode> 039 { 040 /** 041 * Creates a new JSONGetFunction instance. 042 * 043 * @param pointerMap of Map 044 */ 045 @ConstructorProperties("pointerMap") 046 public JSONGetFunction( Map<Fields, String> pointerMap ) 047 { 048 this( asFields( pointerMap.keySet() ), asArray( pointerMap.values() ) ); 049 } 050 051 /** 052 * Creates a new JSONGetFunction instance. 053 * 054 * @param pointerMap of Map 055 * @param failOnMissingNode of boolean 056 */ 057 @ConstructorProperties({"pointerMap", "failOnMissingNode"}) 058 public JSONGetFunction( Map<Fields, String> pointerMap, boolean failOnMissingNode ) 059 { 060 this( asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); 061 } 062 063 /** 064 * Creates a new JSONGetFunction instance. 065 * 066 * @param fieldDeclaration of Fields 067 * @param stringPointers of String... 068 */ 069 @ConstructorProperties({"fieldDeclaration", "stringPointers"}) 070 public JSONGetFunction( Fields fieldDeclaration, String... stringPointers ) 071 { 072 this( fieldDeclaration, false, stringPointers ); 073 } 074 075 /** 076 * Creates a new JSONGetFunction instance. 077 * 078 * @param fieldDeclaration of Fields 079 * @param failOnMissingNode of boolean 080 * @param stringPointers of String... 081 */ 082 @ConstructorProperties({"fieldDeclaration", "failOnMissingNode", "stringPointers"}) 083 public JSONGetFunction( Fields fieldDeclaration, boolean failOnMissingNode, String... stringPointers ) 084 { 085 super( JSONCoercibleType.TYPE, fieldDeclaration, failOnMissingNode, stringPointers ); 086 } 087 088 /** 089 * Creates a new JSONGetFunction instance. 090 * 091 * @param coercibleType of JSONCoercibleType 092 * @param pointerMap of Map 093 */ 094 @ConstructorProperties({"coercibleType", "pointerMap"}) 095 public JSONGetFunction( JSONCoercibleType coercibleType, Map<Fields, String> pointerMap ) 096 { 097 this( coercibleType, asFields( pointerMap.keySet() ), asArray( pointerMap.values() ) ); 098 } 099 100 /** 101 * Creates a new JSONGetFunction instance. 102 * 103 * @param coercibleType of JSONCoercibleType 104 * @param pointerMap of Map 105 * @param failOnMissingNode of boolean 106 */ 107 @ConstructorProperties({"coercibleType", "pointerMap", "failOnMissingNode"}) 108 public JSONGetFunction( JSONCoercibleType coercibleType, Map<Fields, String> pointerMap, boolean failOnMissingNode ) 109 { 110 this( coercibleType, asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); 111 } 112 113 /** 114 * Creates a new JSONGetFunction instance. 115 * 116 * @param coercibleType of JSONCoercibleType 117 * @param fieldDeclaration of Fields 118 * @param stringPointers of String... 119 */ 120 @ConstructorProperties({"coercibleType", "fieldDeclaration", "stringPointers"}) 121 public JSONGetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration, String... stringPointers ) 122 { 123 this( coercibleType, fieldDeclaration, false, stringPointers ); 124 } 125 126 /** 127 * Creates a new JSONGetFunction instance. 128 * 129 * @param coercibleType of JSONCoercibleType 130 * @param fieldDeclaration of Fields 131 * @param failOnMissingNode of boolean 132 * @param stringPointers of String... 133 */ 134 @ConstructorProperties({"coercibleType", "fieldDeclaration", "failOnMissingNode", "stringPointers"}) 135 public JSONGetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration, boolean failOnMissingNode, String... stringPointers ) 136 { 137 super( coercibleType, fieldDeclaration, failOnMissingNode, stringPointers ); 138 } 139 }