@Test public void testParseUser() { InputStream inputStream = getClass().getResourceAsStream("user.json"); User user = converter.parseUser(inputStream); assertNotNull(user); assertEquals("c3a110", user.getId()); assertEquals(2, user.getProfiles().size()); assertEquals("83a112", user.getProfiles().get(0).getId()); assertTrue(user.getProfiles().get(0).getGenotyped()); assertEquals("c92839", user.getProfiles().get(1).getId()); assertTrue(user.getProfiles().get(1).getGenotyped()); }
@Override public User parseUser(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String profileId = null; boolean genotyped = false; List<Profile> profiles = new ArrayList<Profile>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileField)) { profileId = parser.getText(); } else if ("genotyped".equals(profileField)) { genotyped = parser.getBooleanValue(); } } profiles.add(new Profile(profileId, genotyped)); } } } return new User(id, profiles); } catch (IOException e) { logger.warn("could not parse user", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public User parseUser(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String profileId = null; boolean genotyped = false; List<Profile> profiles = new ArrayList<Profile>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileField)) { profileId = parser.getText(); } else if ("genotyped".equals(profileField)) { genotyped = parser.getBooleanValue(); } } profiles.add(new Profile(profileId, genotyped)); } } } return new User(id, profiles); } catch (IOException e) { logger.warn("could not parse user", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public User parseUser(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String profileId = null; boolean genotyped = false; List<Profile> profiles = new ArrayList<Profile>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileField)) { profileId = parser.getText(); } else if ("genotyped".equals(profileField)) { genotyped = parser.getBooleanValue(); } } profiles.add(new Profile(profileId, genotyped)); } } } return new User(id, profiles); } catch (IOException e) { logger.warn("could not parse user", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public User parseUser(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String profileId = null; boolean genotyped = false; List<Profile> profiles = new ArrayList<Profile>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileField)) { profileId = parser.getText(); } else if ("genotyped".equals(profileField)) { genotyped = parser.getBooleanValue(); } } profiles.add(new Profile(profileId, genotyped)); } } } return new User(id, profiles); } catch (IOException e) { logger.warn("could not parse user", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public User parseUser(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String profileId = null; boolean genotyped = false; List<Profile> profiles = new ArrayList<Profile>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("profiles".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String profileField = parser.getCurrentName(); parser.nextToken(); if ("id".equals(profileField)) { profileId = parser.getText(); } else if ("genotyped".equals(profileField)) { genotyped = parser.getBooleanValue(); } } profiles.add(new Profile(profileId, genotyped)); } } } return new User(id, profiles); } catch (IOException e) { logger.warn("could not parse user", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream);  }