Trouble parsing JSON since it splits on the comma

27 views
Skip to first unread message

Devin Bost

unread,
Jul 29, 2020, 6:24:57 PM7/29/20
to jcommander
I'm working on a project that's reading a string message parameter like this:

@Parameter(names = { "-m", "--messages" },
 description
= "Messages to send, either -m or -f or -j must be specified. The default separator is comma",
 splitter
= NoSplitter.class)
private List<String> messages = Lists.newArrayList();

The NoSplitter class implements IParameterSplitter like this:

public class NoSplitter implements IParameterSplitter {
 
@Override
 
public List<String> split(final String value) {
 
final List<String> result = new LinkedList<>();
 result
.add(value);
 
return result;
 
}
}

Unfortunately, whenever I pass a JSON message, such as:
'{ "testKey1": "testValue1", "testKey2": "testValue2" }'

The JSON gets split on the comma, resulting in two malformed JSON messages being received. 

I'm trying to find a solution that will allow me to pass a list of JSON objects, perhaps by allowing me to escape commas that I don't want the splitter to split on. 

Any suggestions? 

Thanks,

Devin

Cédric Beust ♔

unread,
Jul 29, 2020, 6:29:40 PM7/29/20
to jcommander

Hi Devin,

I’m a bit confused, I don’t see any mention of the comma in your NoSplitter class… How does this work?

-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jcommander/a2f6858e-99a5-4c8c-a9fa-a35c2d6c741bo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages