Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonLocation


                                    final String value = getPrimitiveFieldValue(parser.nextToken(), parser.getText());
                                    eventQueue.add(new CharactersEvent(value, new StaxLocation(parser.getCurrentLocation())));
                                } else {
                                    // element event
                                    final QName elementName = getElementQName(fieldName);
                                    final JsonLocation currentLocation = parser.getCurrentLocation();

                                    final boolean isRootEmpty = isEmptyElement(fieldName, true);
                                    if (isRootEmpty) {
                                        eventQueue.add(createStartElementEvent(elementName, new StaxLocation(currentLocation)));
                                        eventQueue.add(createEndElementEvent(elementName, new StaxLocation(currentLocation)));
View Full Code Here


    {
        byte[] data = _smileDoc("[ true, null, false, 511 ]", true); // true -> write header
       
        JsonParser p = _smileParser(data);
        assertNull(p.getCurrentToken());
        JsonLocation loc = p.getCurrentLocation();
        assertNotNull(loc);
        // first: -1 for "not known", for character-based stuff
        assertEquals(-1, loc.getCharOffset());
        // except that with 1.9.7 and above, we also consider column to be same as offset, for convenience
        assertEquals(4, loc.getColumnNr());
        assertEquals(-1, loc.getLineNr());
        // but first 4 bytes are for header
        assertEquals(4, loc.getByteOffset());

        // array marker is a single byte, so:
        assertToken(JsonToken.START_ARRAY, p.nextToken());
        assertEquals(5, p.getCurrentLocation().getByteOffset());
        assertEquals(4, p.getTokenLocation().getByteOffset());
View Full Code Here

                }
            }
        } else if (jsonString.trim().equals("null")) {
            rval = null;
        } else {
            throw new JsonParseException("document doesn't start with a valid json element", new JsonLocation("\""
                    + jsonString.substring(0, Math.min(jsonString.length(), 100)) + "...\"", 0, 1, 0));
        }
        return rval;
    }
View Full Code Here

        }
        context.refresh(outputDirectory);
    }

    private void attachErrorMessage(JsonParseException e) {
        JsonLocation location = e.getLocation();
        File file;
        if (location.getSourceRef() instanceof File) {
            file = (File) location.getSourceRef();
        } else {
            file = null;
        }
        context.addMessage(file, location.getLineNr(), location.getColumnNr(), e.getLocalizedMessage(), BuildContext.SEVERITY_ERROR, e);
    }
View Full Code Here

      return null;
    return parseValue(token);
  }

  private JArray parseArray() throws JsonParseException, IOException {
    JsonLocation loc = jp.getTokenLocation();
    long startPos = loc.getCharOffset();
    int line = loc.getLineNr();
    List<JElement> values = new ArrayList<JElement>();
    for(;;) {
      JsonToken token = jp.nextToken();
      if(token == JsonToken.END_ARRAY) {
        int[] pos = adjustPosition(
          line, (int) startPos, (int) (jp.getCurrentLocation().getCharOffset() - startPos));
        return new JArray(loc.getSourceRef(), pos, values);
      }
      values.add(parseValue(token));
    }
  }
View Full Code Here

      values.add(parseValue(token));
    }
  }

  private JEntry parseField() throws JsonParseException, IOException {
    JsonLocation loc = jp.getTokenLocation();
    long startPos = loc.getCharOffset();
    int line = loc.getLineNr();
    String key = jp.getCurrentName();
    JElement value = parseValue(jp.nextToken());

    // We get weird positions from the parser that includes whitespace etc. We adjust
    // that here
    int[] pos = adjustPosition(line, (int) startPos, (int) (jp.getCurrentLocation().getCharOffset() - startPos));
    return new JEntry(loc.getSourceRef(), pos, key, value);
  }
View Full Code Here

    int[] pos = adjustPosition(line, (int) startPos, (int) (jp.getCurrentLocation().getCharOffset() - startPos));
    return new JEntry(loc.getSourceRef(), pos, key, value);
  }

  private JObject parseObject() throws JsonParseException, IOException {
    JsonLocation loc = jp.getTokenLocation();
    long startPos = loc.getCharOffset();
    int line = loc.getLineNr();
    List<JEntry> entries = new ArrayList<JEntry>();
    for(;;) {
      switch(jp.nextToken()) {
        case END_OBJECT:
          int[] pos = adjustPosition(
            line, (int) startPos, (int) (jp.getCurrentLocation().getCharOffset() - startPos));
          return new JObject(loc.getSourceRef(), pos, entries);
        case FIELD_NAME:
          entries.add(parseField());
          continue;
        default:
          throw new JsonParseException("Field name expected", jp.getTokenLocation());
View Full Code Here

      }
    }
  }

  private JElement parseValue(JsonToken token) throws JsonParseException, IOException {
    JsonLocation loc = jp.getCurrentLocation();
    long startPos = loc.getCharOffset();
    int line = loc.getLineNr();
    switch(token) {
      case START_ARRAY:
        return parseArray();
      case START_OBJECT:
        return parseObject();
      case VALUE_FALSE:
      case VALUE_NULL:
      case VALUE_TRUE:
      case VALUE_NUMBER_FLOAT:
      case VALUE_NUMBER_INT:
      case VALUE_STRING:
        Object value = null;
        switch(token) {
          case VALUE_FALSE:
            value = Boolean.FALSE;
            break;
          case VALUE_TRUE:
            value = Boolean.TRUE;
            break;
          case VALUE_NUMBER_FLOAT:
            value = jp.getDoubleValue();
            break;
          case VALUE_NUMBER_INT:
            value = jp.getLongValue();
            break;
          case VALUE_STRING:
            value = jp.getText();
        }
        long endPos = jp.getCurrentLocation().getCharOffset();
        int[] pos = adjustPosition(line, (int) startPos, (int) (endPos - startPos));
        return new JPrimitive(loc.getSourceRef(), pos, value);
      default:
        throw new JsonParseException("Value expected", loc);
    }
  }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.JsonLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.