java - Restructuring data into nested maps - override put to avoid null? -


i need dump list of complicated java objects in yaml. needed structure first converted them nested lists , maps. it's kind of like:

- item 1     name : value     name : value         - list         ... - item 2 ... 

or in eclipses debugger view [...,...] list , {name:value,name:value} map looks [{item1={name:value, name:value[{anotherlist}]}item2=...]. it's mess, it's not long , not difficult understand, tedious.

the problem few of theses blocks optional, few empty lists or null values:

- item 1     null : null     name : [] - item 2 , on 

which messy , can't read in again. , can't check 1 of higher level lists or maps because might contain empty lists, empty maps or nulls. don't want write if (value != null && !value.isempty) on , on again. see have 3 options:

  • i technically modify template, don't want mess if don't have to. go on whole construct afterwards , take out nulls , empty constructs. manually writing long , nested , recursion if (value.islist) , if (value.ismap) time doesn't sound great either.
  • i write

    private map putunlessnullorempty(map, name, value)  private list addunlessnullorempty(list, name, value) 

methods. that's did, looks unjavaish.

  • it'd great if add these methods lists , maps in class. or override/overload put/add methods. write separate classes (or inner classes) extending usual maps , lists, method. sounds kind of excessive.

i'm not experienced java or programming in general yet. think?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -