public static Lockfile read(Reader data) throws LockfileParseException, IOException {
Set<LockfileRequirement> requirements = null;
Set<LockfileContext> contexts = null;
Set<LockfileArtifact> artifacts = null;
JsonParser parser = new JsonFactory().createParser(data);
try {
// Get START_OBJECT
parser.nextToken();
// Read field name or END_OBJECT
while (parser.nextToken() != JsonToken.END_OBJECT) {
assert (parser.getCurrentToken() == JsonToken.FIELD_NAME);
String fieldName = parser.getCurrentName();
// Read value, or START_OBJECT/START_ARRAY
parser.nextToken();
if (fieldName.equals("requirements")) {
requirements = new HashSet<LockfileRequirement>();
while (parser.nextToken() != JsonToken.END_ARRAY) {
requirements.add(parseRequirement(parser));
}
} else if (fieldName.equals("context")) {
contexts = new HashSet<LockfileContext>();
while (parser.nextToken() != JsonToken.END_ARRAY) {
contexts.add(parseContext(parser));
}
} else if (fieldName.equals("artifacts")) {
artifacts = new HashSet<LockfileArtifact>();
while (parser.nextToken() != JsonToken.END_ARRAY) {
artifacts.add(parseArtifact(parser));
}
}
}
}
finally {
parser.close();
}
return new Lockfile(requirements, contexts, artifacts);
}