1

I want to change "cadena.toString()" by the value of the String and execute the last line.

    Map<String, String> config = new HashMap<String, String>();
    JsonBuilderFactory factory = Json.createBuilderFactory(config);

    JsonObject value = null ;
    StringBuffer cadena = new StringBuffer("");

    for(Friendship f: listFriends){ 
          cadena.append( ".add( \"From: "+f.getUser_from().getLogin()+"\",\"To: "+ f.getUser_to().getLogin()+"\")");
     }

     value = factory.createObjectBuilder().cadena.toString().build();

It's possible?

Many thanks to all and sorry for my poor English.

Aniru
  • 165
  • 2
  • 10

1 Answers1

1

No. Your first clue should be that factory.createObjectBuilder().cadena (probably) won't even compile.

Why can't you do something like this?

(note: replace Builder with the correct object type of factory.createObjectBuilder() return value)

Builder b = factory.createObjectBuilder();
for(Friendship f: listFriends){ 
      b.add("From: "+f.getUser_from().getLogin()+", To: "+ f.getUser_to().getLogin());
}
value = b.build();
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Whatever this `createObjectBuilder` returns, I do not know. This code wasn't intended to be copy and pasted. Just an example of what you seem to want to be using instead – OneCricketeer Nov 26 '16 at 18:37