joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.22k stars 1.66k forks source link

Can't get fileFilter working with gradle plugin #1595

Closed pgalbraith closed 5 months ago

pgalbraith commented 5 months ago

I just want the gradle plugin to process *.json schema files and ignore anything that's not *.json. This is proving to be very difficult, however. I don't doubt that this is just lack of awareness on my part to make it work correctly, but I'm really struggling to make fileFilter work.

Looking at the documentation (https://github.com/joelittlejohn/jsonschema2pojo/tree/master/jsonschema2pojo-gradle-plugin#usage) it suggests I can apply the default filter with fileFilter = new AllFileFilter(). However, trying that verbatim yields a build error unable to resolve class AllFileFilter.

I get the same error if I fully qualify the filter, fileFilter = new org.jsonschema2pojo.AllFileFilter(): unable to resolve class org.json2schema2pojo.AllFileFilter.

What I really want is to be able to specify a custom filter ala fileFilter = { it.name.endsWith('.json') } but I just can't seem to get anything to work. Would it possible to show a working example of a fileFilter defined in a gradle script?

unkish commented 5 months ago

Hi

Maybe something like

fileFilter = file -> file.path.endsWith('.json')

would do the trick ?

pgalbraith commented 5 months ago

Thanks @unkish ... I finally figured it was failing because it's walking the entire tree and the lambda was returning false for the parent directory and thus not even looking at the schema files. This value of fileFilter does the trick:

fileFilter = { it.isDirectory() || it.name.endsWith('.json') }