Hi Olafur, Thank you very much for your suggestion. You're right, there is no strict requirement to make the fields() call on the LoaderJSONStep API mandatory (same with LoaderCSVStep and LoaderRowsStep). While it may not always be possible to derive field names from input data (the JSON header info is optional also when exporting data), we can definitely use it when it is present. So, either we make this step completely optional, or offer an additional fieldsFromSource() method that indicates that we want to use the source specification. I tend to prefer the latter.
In any case, I have registered a feature request for this: https://github.com/jOOQ/jOOQ/issues/8755 Thanks again for your suggestion! Lukas On Thu, Jun 6, 2019 at 6:43 PM Olafur Bragason <[email protected]> wrote: > When loading a JSON export like: > jooq.loadInto(table) > .loadJSON(...) > .fields(field1, ..., fieldsN) > .execute(); > you need to specify the fields even if the JSON already contains the field > information. > This seems unnecessary and brittle. > > I made a proof of concept change to jOOQ which seems to work, at least for > my test cases. > > I added LoaderJSONOptionsStep<R> fieldsFromJSON() to LoaderJSONStep > and an implementation to LoaderImpl that only sets a flag fieldsFromJSON: > > @Override > public final LoaderImpl<R> fieldsFromJSON() { > this.fieldsFromJSON = true; > return this; > } > > The only change needed to LoaderImpl.executeJSON() is to set fields to > source if the new fieldsFromJSON flag is set: > > private void executeJSON() throws IOException { > ... > source = r.fields(); // old > if(this.fieldsFromJSON) // new > fields = source; // new > ... > } > > The new JSON load looks like this: > jooq.loadInto(table) > .loadJSON(...) > .fieldsFromJSON() > .execute(); > > Please consider adding this feature to jOOQ. > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jooq-user/0d5172c5-56a6-4f60-b7d0-ddd22f169583%40googlegroups.com > <https://groups.google.com/d/msgid/jooq-user/0d5172c5-56a6-4f60-b7d0-ddd22f169583%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAB4ELO55zgkvjbuDGRxAqNNsca7ij%3DRGs8ye7orn%3D6TAsjws9A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
