public void EnsureJSONParserHandlesgetLocalNameCorrectly() throws Exception{
String sampleJson = "{\"field\":\"value\"}";
String sampleJson2 = "{\"field\":{}}";
String sampleJson3 = "{\"field\":[{},{}]}";
JSONTreeReader parser = new JSONTreeReader(new StringReader(sampleJson));
Token token = Token.Ignorable;
int i = 0;
try{
while(token != null){
token = parser.next();
if(token == null) {
break;
}
i++;
if(i == 3){
Assert.assertEquals(Token.Value, token);
Assert.assertEquals("field", parser.getFieldName());
}
}
}catch(Exception e){
//silent
}
parser = new JSONTreeReader(new StringReader(sampleJson2));
token = Token.Ignorable;
i = 0;
try{
while(token != null){
token = parser.next();
if(token == null) {
break;
}
i++;
if(i == 3){
Assert.assertEquals(Token.StartEntity, token);
Assert.assertEquals(parser.getFieldName(), "field");
}
}
}catch(Exception e){
//silent
}
parser = new JSONTreeReader(new StringReader(sampleJson3));
token = Token.Ignorable;
i = 0;
try{
while(token != null){
token = parser.next();
if(token == null) {
break;
}
i++;
if(i == 3){
Assert.assertEquals(token, Token.StartEntity);
Assert.assertEquals(parser.getFieldName(), "field");
}
if(i == 4){
Assert.assertEquals(token, Token.StartEntity);
Assert.assertEquals(parser.getFieldName(), JsonImporter.ANONYMOUS);
}
if(i == 6){
Assert.assertEquals(token, Token.StartEntity);
Assert.assertEquals(parser.getFieldName(), JsonImporter.ANONYMOUS);
}
}
}catch(Exception e){
//silent
}