List of usage examples for com.fasterxml.jackson.core JsonParser getValueAsBoolean
public boolean getValueAsBoolean() throws IOException, JsonParseException
From source file:com.google.openrtb.json.OpenRtbJsonReader.java
@SuppressWarnings("deprecation") protected void readBannerField(JsonParser par, Banner.Builder banner, String fieldName) throws IOException { switch (fieldName) { case "w": banner.setW(par.getIntValue());/*ww w . java 2 s . com*/ break; case "h": banner.setH(par.getIntValue()); break; case "wmax": banner.setWmax(par.getIntValue()); break; case "hmax": banner.setHmax(par.getIntValue()); break; case "wmin": banner.setWmin(par.getIntValue()); break; case "hmin": banner.setHmin(par.getIntValue()); break; case "id": banner.setId(par.getText()); break; case "btype": for (startArray(par); endArray(par); par.nextToken()) { BannerAdType value = BannerAdType.valueOf(par.getIntValue()); if (checkEnum(value)) { banner.addBtype(value); } } break; case "battr": for (startArray(par); endArray(par); par.nextToken()) { CreativeAttribute value = CreativeAttribute.valueOf(par.getIntValue()); if (checkEnum(value)) { banner.addBattr(value); } } break; case "pos": { AdPosition value = AdPosition.valueOf(par.getIntValue()); if (checkEnum(value)) { banner.setPos(value); } } break; case "mimes": for (startArray(par); endArray(par); par.nextToken()) { banner.addMimes(par.getText()); } break; case "topframe": banner.setTopframe(par.getValueAsBoolean()); break; case "expdir": for (startArray(par); endArray(par); par.nextToken()) { ExpandableDirection value = ExpandableDirection.valueOf(par.getIntValue()); if (checkEnum(value)) { banner.addExpdir(value); } } break; case "api": for (startArray(par); endArray(par); par.nextToken()) { APIFramework value = APIFramework.valueOf(par.getIntValue()); if (checkEnum(value)) { banner.addApi(value); } } break; case "format": for (startArray(par); endArray(par); par.nextToken()) { banner.addFormat(readFormat(par)); } break; default: readOther(banner, par, fieldName); } }
From source file:com.google.openrtb.json.OpenRtbJsonReader.java
@SuppressWarnings("deprecation") protected void readVideoField(JsonParser par, Video.Builder video, String fieldName) throws IOException { switch (fieldName) { case "mimes": for (startArray(par); endArray(par); par.nextToken()) { video.addMimes(par.getText()); }// w ww. j a va2 s.com break; case "minduration": video.setMinduration(par.getIntValue()); break; case "maxduration": video.setMaxduration(par.getIntValue()); break; case "protocol": { Protocol value = Protocol.valueOf(par.getIntValue()); if (checkEnum(value)) { video.setProtocol(value); } } break; case "protocols": for (startArray(par); endArray(par); par.nextToken()) { Protocol value = Protocol.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addProtocols(value); } } break; case "w": video.setW(par.getIntValue()); break; case "h": video.setH(par.getIntValue()); break; case "startdelay": video.setStartdelay(par.getIntValue()); break; case "linearity": { VideoLinearity value = VideoLinearity.valueOf(par.getIntValue()); if (checkEnum(value)) { video.setLinearity(value); } } break; case "sequence": video.setSequence(par.getIntValue()); break; case "battr": for (startArray(par); endArray(par); par.nextToken()) { CreativeAttribute value = CreativeAttribute.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addBattr(value); } } break; case "maxextended": video.setMaxextended(par.getIntValue()); break; case "minbitrate": video.setMinbitrate(par.getIntValue()); break; case "maxbitrate": video.setMaxbitrate(par.getIntValue()); break; case "boxingallowed": video.setBoxingallowed(par.getValueAsBoolean()); break; case "playbackmethod": for (startArray(par); endArray(par); par.nextToken()) { PlaybackMethod value = PlaybackMethod.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addPlaybackmethod(value); } } break; case "delivery": for (startArray(par); endArray(par); par.nextToken()) { ContentDeliveryMethod value = ContentDeliveryMethod.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addDelivery(value); } } break; case "pos": { AdPosition value = AdPosition.valueOf(par.getIntValue()); if (checkEnum(value)) { video.setPos(value); } } break; case "companionad": if (peekStructStart(par) == JsonToken.START_ARRAY) { // OpenRTB 2.2+ for (startArray(par); endArray(par); par.nextToken()) { video.addCompanionad(readBanner(par)); } } else { // START_OBJECT // OpenRTB 2.1- video.setCompanionad21(readCompanionAd(par)); } break; case "api": for (startArray(par); endArray(par); par.nextToken()) { APIFramework value = APIFramework.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addApi(value); } } break; case "companiontype": for (startArray(par); endArray(par); par.nextToken()) { CompanionType value = CompanionType.valueOf(par.getIntValue()); if (checkEnum(value)) { video.addCompaniontype(value); } } break; case "skip": video.setSkip(par.getValueAsBoolean()); break; case "skipmin": video.setSkipmin(par.getIntValue()); break; case "skipafter": video.setSkipafter(par.getIntValue()); break; default: readOther(video, par, fieldName); } }
From source file:com.google.openrtb.json.OpenRtbJsonReader.java
@SuppressWarnings("deprecation") protected void readContentField(JsonParser par, Content.Builder content, String fieldName) throws IOException { switch (fieldName) { case "id": content.setId(par.getText());//from w ww . ja v a 2s. c om break; case "episode": content.setEpisode(par.getIntValue()); break; case "title": content.setTitle(par.getText()); break; case "series": content.setSeries(par.getText()); break; case "season": content.setSeason(par.getText()); break; case "producer": content.setProducer(readProducer(par)); break; case "url": content.setUrl(par.getText()); break; case "cat": for (startArray(par); endArray(par); par.nextToken()) { String cat = par.getText(); if (checkContentCategory(cat)) { content.addCat(cat); } } break; case "videoquality": { ProductionQuality value = ProductionQuality.valueOf(par.getIntValue()); if (checkEnum(value)) { content.setVideoquality(value); } } break; case "context": try { // JsonParseException may be thrown because value is string in // 2.2 and earlier, this allows for backwards compatibility. ContentContext value = ContentContext.valueOf(par.getIntValue()); if (checkEnum(value)) { content.setContext(value); } } catch (JsonParseException jpe) { } break; case "contentrating": content.setContentrating(par.getText()); break; case "userrating": content.setUserrating(par.getText()); break; case "qagmediarating": { QAGMediaRating value = QAGMediaRating.valueOf(par.getIntValue()); if (checkEnum(value)) { content.setQagmediarating(value); } } break; case "keywords": content.setKeywords(readCsvString(par)); break; case "livestream": content.setLivestream(par.getValueAsBoolean()); break; case "sourcerelationship": content.setSourcerelationship(par.getValueAsBoolean()); break; case "len": content.setLen(par.getIntValue()); break; case "language": content.setLanguage(par.getText()); break; case "embeddable": content.setEmbeddable(par.getValueAsBoolean()); break; case "artist": content.setArtist(par.getText()); break; case "genre": content.setGenre(par.getText()); break; case "album": content.setAlbum(par.getText()); break; case "isrc": content.setIsrc(par.getText()); break; case "prodq": { ProductionQuality value = ProductionQuality.valueOf(par.getIntValue()); if (checkEnum(value)) { content.setProdq(value); } } break; default: readOther(content, par, fieldName); } }
From source file:com.google.openrtb.json.OpenRtbJsonReader.java
protected void readAudioField(JsonParser par, Audio.Builder audio, String fieldName) throws IOException { // Video & Audio common switch (fieldName) { case "mimes": for (startArray(par); endArray(par); par.nextToken()) { audio.addMimes(par.getText()); }// w w w . j av a 2s . c o m break; case "minduration": audio.setMinduration(par.getIntValue()); break; case "maxduration": audio.setMaxduration(par.getIntValue()); break; case "protocols": for (startArray(par); endArray(par); par.nextToken()) { Protocol value = Protocol.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.addProtocols(value); } } break; case "startdelay": audio.setStartdelay(par.getIntValue()); break; case "sequence": audio.setSequence(par.getIntValue()); break; case "battr": for (startArray(par); endArray(par); par.nextToken()) { CreativeAttribute value = CreativeAttribute.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.addBattr(value); } } break; case "maxextended": audio.setMaxextended(par.getIntValue()); break; case "minbitrate": audio.setMinbitrate(par.getIntValue()); break; case "maxbitrate": audio.setMaxbitrate(par.getIntValue()); break; case "delivery": for (startArray(par); endArray(par); par.nextToken()) { ContentDeliveryMethod value = ContentDeliveryMethod.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.addDelivery(value); } } break; case "companionad": if (peekStructStart(par) == JsonToken.START_ARRAY) { // OpenRTB 2.2+ for (startArray(par); endArray(par); par.nextToken()) { audio.addCompanionad(readBanner(par)); } } break; case "api": for (startArray(par); endArray(par); par.nextToken()) { APIFramework value = APIFramework.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.addApi(value); } } break; case "companiontype": for (startArray(par); endArray(par); par.nextToken()) { CompanionType value = CompanionType.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.addCompaniontype(value); } } break; // Audio only case "maxseq": audio.setMaxseq(par.getIntValue()); break; case "feed": { FeedType feed = FeedType.valueOf(par.getIntValue()); if (checkEnum(feed)) { audio.setFeed(feed); } } break; case "stitched": audio.setStitched(par.getValueAsBoolean()); break; case "nvol": { VolumeNormalizationMode value = VolumeNormalizationMode.valueOf(par.getIntValue()); if (checkEnum(value)) { audio.setNvol(value); } } break; default: readOther(audio, par, fieldName); } }
From source file:com.ntsync.shared.RawContact.java
/** * Creates and returns an instance of the RawContact from encrypted data * // w ww .j a v a 2s. com * */ public static RawContact valueOf(String rowId, Map<Byte, ByteBuffer> values, Key privateKey) throws InvalidKeyException { try { String serverContactId = null; long rawContactId = -1; if (values.containsKey(ContactConstants.SERVERROW_ID)) { serverContactId = readRawString(values.get(ContactConstants.SERVERROW_ID)); } String lastModStr = readRawString(values.get(ContactConstants.MODIFIED)); Date lastModified = null; if (lastModStr != null) { lastModified = new Date(Long.parseLong(lastModStr)); } if (serverContactId == null || !serverContactId.equals(rowId)) { // If ServerContactId is different, then rowId is the clientId rawContactId = Long.parseLong(rowId); } if (serverContactId == null && rawContactId < 0) { throw new IllegalArgumentException("Missing RowId in data"); } AEADBlockCipher cipher = CryptoHelper.getCipher(); final boolean deleted = values.containsKey(ContactConstants.DELETED); final String textData = CryptoHelper.decodeStringValue(ContactConstants.TEXTDATA, values, cipher, privateKey); if (textData == null && !deleted) { LOG.error("No textdata found for row with Id:" + rowId); return null; } String fullName = null; String firstName = null; String lastName = null; String middleName = null; String prefixName = null; String suffixName = null; String phonecticFirst = null; String phonecticMiddle = null; String phonecticLast = null; List<String> groupSourceIds = null; String note = null; List<ListRawData<PhoneType>> phones = null; List<ListRawData<EmailType>> emails = null; List<ListRawData<WebsiteType>> websites = null; List<ListRawData<EventType>> events = null; List<ListRawData<RelationType>> relations = null; List<ListRawData<SipAddressType>> sipaddresses = null; List<ListRawData<NicknameType>> nicknames = null; List<RawAddressData> addresses = null; List<RawImData> imAddresses = null; RawOrganizationData organization = null; boolean photoSuperPrimary = false; boolean starred = false; String customRingtone = null; boolean sendToVoiceMail = false; if (!SyncDataHelper.isEmpty(textData)) { JsonFactory fac = new JsonFactory(); JsonParser jp = fac.createParser(textData); jp.nextToken(); while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); // move to value, or START_OBJECT/START_ARRAY jp.nextToken(); if (ContactConstants.STRUCTUREDNAME.equals(fieldname)) { while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); // move to value if (jp.nextToken() == null) { throw new JsonParseException("Invalid JSON-Structure. End of Object missing.", jp.getCurrentLocation()); } if (ContactConstants.DISPLAY_NAME.equals(namefield)) { fullName = jp.getValueAsString(); } else if (ContactConstants.FAMILY_NAME.equals(namefield)) { lastName = jp.getValueAsString(); } else if (ContactConstants.GIVEN_NAME.equals(namefield)) { firstName = jp.getValueAsString(); } else if (ContactConstants.MIDDLE_NAME.equals(namefield)) { middleName = jp.getValueAsString(); } else if (ContactConstants.SUFFIX_NAME.equals(namefield)) { suffixName = jp.getValueAsString(); } else if (ContactConstants.PREFIX_NAME.equals(namefield)) { prefixName = jp.getValueAsString(); } else if (ContactConstants.PHONETIC_FAMILY.equals(namefield)) { phonecticLast = jp.getValueAsString(); } else if (ContactConstants.PHONETIC_GIVEN.equals(namefield)) { phonecticFirst = jp.getValueAsString(); } else if (ContactConstants.PHONETIC_MIDDLE.equals(namefield)) { phonecticMiddle = jp.getValueAsString(); } else { LOG.error("Unrecognized structurednamefield for row with Id:" + rowId + " Fieldname:" + fieldname); break; } } } else if (ContactConstants.STRUCTUREDPOSTAL.equals(fieldname)) { addresses = readAddressList(rowId, addresses, jp); } else if (ContactConstants.PHONE.equals(fieldname)) { phones = readJsonList(rowId, phones, jp, fieldname, PhoneType.TYPE_OTHER, PhoneType.class); } else if (ContactConstants.EMAIL.equals(fieldname)) { emails = readJsonList(rowId, emails, jp, fieldname, EmailType.TYPE_OTHER, EmailType.class); } else if (ContactConstants.WEBSITE.equals(fieldname)) { websites = readJsonList(rowId, websites, jp, fieldname, WebsiteType.TYPE_OTHER, WebsiteType.class); } else if (ContactConstants.EVENT.equals(fieldname)) { events = readJsonList(rowId, events, jp, fieldname, EventType.TYPE_OTHER, EventType.class); } else if (ContactConstants.RELATION.equals(fieldname)) { relations = readJsonList(rowId, relations, jp, fieldname, RelationType.TYPE_CUSTOM, RelationType.class); } else if (ContactConstants.SIPADDRESS.equals(fieldname)) { sipaddresses = readJsonList(rowId, sipaddresses, jp, fieldname, SipAddressType.TYPE_OTHER, SipAddressType.class); } else if (ContactConstants.NICKNAME.equals(fieldname)) { nicknames = readJsonList(rowId, nicknames, jp, fieldname, NicknameType.TYPE_DEFAULT, NicknameType.class); } else if (ContactConstants.IM.equals(fieldname)) { imAddresses = readImList(rowId, imAddresses, jp); } else if (ContactConstants.NOTE.equals(fieldname)) { note = jp.getValueAsString(); } else if (ContactConstants.GROUPMEMBERSHIP.equals(fieldname)) { while (jp.nextToken() != JsonToken.END_ARRAY) { String groupSourceId = jp.getValueAsString(); if (groupSourceIds == null) { groupSourceIds = new ArrayList<String>(); } groupSourceIds.add(groupSourceId); } } else if (ContactConstants.ORGANIZATION.equals(fieldname)) { organization = readOrg(rowId, jp); } else if (ContactConstants.PHOTO_SUPERPRIMARY.equals(fieldname)) { photoSuperPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.STARRED.equals(fieldname)) { starred = jp.getValueAsBoolean(); } else if (ContactConstants.SEND_TO_VOICE_MAIL.equals(fieldname)) { sendToVoiceMail = jp.getValueAsBoolean(); } else if (ContactConstants.DROID_CUSTOM_RINGTONE.equals(fieldname)) { customRingtone = jp.getValueAsString(); } else { LOG.error("Unrecognized field for row with Id:" + rowId + " Fieldname:" + fieldname); } } jp.close(); } final byte[] photo = CryptoHelper.decodeValue(ContactConstants.PHOTO, values, cipher, privateKey); return new RawContact(fullName, firstName, lastName, middleName, prefixName, suffixName, phonecticFirst, phonecticMiddle, phonecticLast, phones, emails, websites, addresses, events, relations, sipaddresses, nicknames, imAddresses, note, organization, photo, photoSuperPrimary, groupSourceIds, null, starred, customRingtone, sendToVoiceMail, lastModified, deleted, serverContactId, rawContactId, false, -1); } catch (InvalidCipherTextException ex) { throw new InvalidKeyException("Invalid key detected.", ex); } catch (final IOException ex) { LOG.info("Error parsing contact data. Reason:" + ex.toString(), ex); } catch (IllegalArgumentException ex) { LOG.warn("Error parsing contact data. Reason:" + ex.toString(), ex); } return null; }