@Test public void countMatches () throws ManipulationException { String pluginsPath = "$..plugins"; String reposURLPath = "$.repository.url"; try { DocumentContext doc = jsonIO.parseJSON( pluginFile ); List o = doc.read ( pluginsPath ); assertEquals( 1, o.size() ); o = doc.read ( reposURLPath ); assertEquals( 1, o.size() ); } catch (JsonPathException e) { throw new ManipulationException( "Caught JsonPath", e ); } }
public DocumentContext parseJSON( File jsonFile ) throws ManipulationException { if ( jsonFile == null || !jsonFile.exists() ) { throw new ManipulationException( "JSON File not found" ); } this.encoding = detectEncoding( jsonFile ); this.charset = Charset.forName( encoding.getJavaName() ); this.jsonFile = jsonFile; this.eol = detectEOL( jsonFile ); DocumentContext doc; try ( FileInputStream in = new FileInputStream( jsonFile ) ) { Configuration conf = Configuration.builder().options( Option.ALWAYS_RETURN_LIST ).build(); doc = JsonPath.using( conf ).parse( in, charset.name() ); } catch ( IOException e ) { logger.error( "Unable to parse JSON File", e ); throw new ManipulationException( "Unable to parse JSON File", e ); } return doc; }
JSONIO { public DocumentContext parseJSON( File jsonFile ) throws ManipulationException { if ( jsonFile == null || !jsonFile.exists() ) { throw new ManipulationException( "JSON File not found" ); } this.encoding = detectEncoding( jsonFile ); this.charset = Charset.forName( encoding.getJavaName() ); this.jsonFile = jsonFile; this.eol = detectEOL( jsonFile ); DocumentContext doc; try ( FileInputStream in = new FileInputStream( jsonFile ) ) { Configuration conf = Configuration.builder().options( Option.ALWAYS_RETURN_LIST ).build(); doc = JsonPath.using( conf ).parse( in, charset.name() ); } catch ( IOException e ) { logger.error( "Unable to parse JSON File", e ); throw new ManipulationException( "Unable to parse JSON File", e ); } return doc; } }
JSONIO { public DocumentContext parseJSON( File jsonFile ) throws ManipulationException { if ( jsonFile == null || !jsonFile.exists() ) { throw new ManipulationException( "JSON File not found" ); } this.encoding = detectEncoding( jsonFile ); this.charset = Charset.forName( encoding.getJavaName() ); this.jsonFile = jsonFile; this.eol = detectEOL( jsonFile ); DocumentContext doc; try ( FileInputStream in = new FileInputStream( jsonFile ) ) { Configuration conf = Configuration.builder().options( Option.ALWAYS_RETURN_LIST ).build(); doc = JsonPath.using( conf ).parse( in, charset.name() ); } catch ( IOException e ) { logger.error( "Unable to parse JSON File", e ); throw new ManipulationException( "Unable to parse JSON File", e ); } return doc; }  }
JSONIO { public DocumentContext parseJSON( File jsonFile ) throws ManipulationException { if ( jsonFile == null || !jsonFile.exists() ) { throw new ManipulationException( "JSON File not found" ); } this.encoding = detectEncoding( jsonFile ); this.charset = Charset.forName( encoding.getJavaName() ); this.jsonFile = jsonFile; this.eol = detectEOL( jsonFile ); DocumentContext doc; try ( FileInputStream in = new FileInputStream( jsonFile ) ) { Configuration conf = Configuration.builder().options( Option.ALWAYS_RETURN_LIST ).build(); doc = JsonPath.using( conf ).parse( in, charset.name() ); } catch ( IOException e ) { logger.error( "Unable to parse JSON File", e ); throw new ManipulationException( "Unable to parse JSON File", e ); } return doc; }  static JsonEncoding detectEncoding(File jsonFile); JsonEncoding getEncoding(); Charset getCharset(); String detectEOL( File jsonFile ); String getEOL(); DocumentContext parseJSON( File jsonFile ); void writeJSON( File target, DocumentContext contents ); }
JSONIO { public DocumentContext parseJSON( File jsonFile ) throws ManipulationException { if ( jsonFile == null || !jsonFile.exists() ) { throw new ManipulationException( "JSON File not found" ); } this.encoding = detectEncoding( jsonFile ); this.charset = Charset.forName( encoding.getJavaName() ); this.jsonFile = jsonFile; this.eol = detectEOL( jsonFile ); DocumentContext doc; try ( FileInputStream in = new FileInputStream( jsonFile ) ) { Configuration conf = Configuration.builder().options( Option.ALWAYS_RETURN_LIST ).build(); doc = JsonPath.using( conf ).parse( in, charset.name() ); } catch ( IOException e ) { logger.error( "Unable to parse JSON File", e ); throw new ManipulationException( "Unable to parse JSON File", e ); } return doc; }  static JsonEncoding detectEncoding(File jsonFile); JsonEncoding getEncoding(); Charset getCharset(); String detectEOL( File jsonFile ); String getEOL(); DocumentContext parseJSON( File jsonFile ); void writeJSON( File target, DocumentContext contents );  }