javax.json.JsonException Java Examples
The following examples show how to use
javax.json.JsonException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONNamedAssociationState.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public boolean put( String name, EntityReference entityReference ) { try { if( containsName( name ) && entityReference.identity().toString().equals( getReferences().getString( name ) ) ) { return false; } entityState.stateCloneAddNamedAssociation( stateName, name, entityReference ); entityState.markUpdated(); return true; } catch( JsonException ex ) { throw new EntityStoreException( ex ); } }
Example #2
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public JsonObject removeManyAssociation( MigrationContext context, JsonObject state, String name ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.manyAssociationRemoved( state.getString( JSONKeys.IDENTITY ), name ); } return migratedState; } else { context.addFailure( "Remove many-association " + name ); return state; } }
Example #3
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public JsonObject removeNamedAssociation( MigrationContext context, JsonObject state, String name ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( !valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.namedAssociationRemoved( state.getString( JSONKeys.IDENTITY ), name ); } return migratedState; } else { context.addFailure( "Remove named-association " + name ); return state; } }
Example #4
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public JsonObject changeEntityType( MigrationContext context, JsonObject state, String fromType, String toType ) throws JsonException { String currentType = state.getString( JSONKeys.TYPE ); if( fromType.equals( currentType ) ) { JsonObject migratedState = jsonFactories.cloneBuilder( state ) .add( JSONKeys.TYPE, toType ) .build(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.entityTypeChanged( state.getString( JSONKeys.IDENTITY ), toType ); } return migratedState; } else { context.addFailure( "Change entity type from " + fromType + " to " + toType ); return state; } }
Example #5
Source File: WeiboStatus.java From albert with MIT License | 6 votes |
public static StatusWapper constructWapperStatus(JsonObject res) throws WeiboException { // JsonObject jsonStatus = res.asJsonObject(); // asJsonArray(); JsonObject jsonStatus = res; JsonArray statuses = null; try { if (!jsonStatus.isNull("statuses")) { statuses = jsonStatus.getJsonArray("statuses"); } int size = statuses.size(); List<WeiboStatus> status = new ArrayList<WeiboStatus>(size); for (int i = 0; i < size; i++) { status.add(new WeiboStatus(statuses.getJsonObject(i))); } long previousCursor = jsonStatus.getJsonNumber("previous_cursor").longValue(); long nextCursor = jsonStatus.getJsonNumber("next_cursor").longValue(); long totalNumber = jsonStatus.getJsonNumber("total_number").longValue(); String hasvisible = String.valueOf(jsonStatus.getBoolean("hasvisible")); return new StatusWapper(status, previousCursor, nextCursor, totalNumber, hasvisible); } catch (JsonException jsone) { throw new WeiboException(jsone); } }
Example #6
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public JsonObject removeAssociation( MigrationContext context, JsonObject state, String name ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.associationRemoved( state.getString( JSONKeys.IDENTITY ), name ); } return migratedState; } else { context.addFailure( "Remove association " + name ); return state; } }
Example #7
Source File: RsPrettyJson.java From takes with MIT License | 6 votes |
/** * Format body with proper indents. * @param body Response body * @return New properly formatted body * @throws IOException If fails */ private static byte[] transform(final InputStream body) throws IOException { final ByteArrayOutputStream res = new ByteArrayOutputStream(); try (JsonReader rdr = Json.createReader(body)) { final JsonObject obj = rdr.readObject(); try (JsonWriter wrt = Json.createWriterFactory( Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true) ) .createWriter(res) ) { wrt.writeObject(obj); } } catch (final JsonException ex) { throw new IOException(ex); } return res.toByteArray(); }
Example #8
Source File: JSONManyAssociationState.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public boolean add( int idx, EntityReference entityReference ) { try { if( indexOfReference( entityReference.identity().toString() ) != -1 ) { return false; } entityState.stateCloneAddManyAssociation( idx, stateName, entityReference ); entityState.markUpdated(); return true; } catch( JsonException e ) { throw new EntityStoreException( e ); } }
Example #9
Source File: WeiboUser.java From albert with MIT License | 6 votes |
/** * * @param res * @return * @throws WeiboException */ public static UserWapper constructWapperUsers(JsonObject res) throws WeiboException { logger.trace(res.toString()); JsonObject jsonUsers = res; // asJsonArray(); try { JsonArray user = jsonUsers.getJsonArray("users"); int size = user.size(); List<WeiboUser> users = new ArrayList<WeiboUser>(size); for (int i = 0; i < size; i++) { users.add(new WeiboUser(user.getJsonObject(i))); } long previousCursor = WeiboResponseUtil.getLong("previous_curosr", jsonUsers); long nextCursor = WeiboResponseUtil.getLong("next_cursor", jsonUsers); long totalNumber = WeiboResponseUtil.getLong("total_number", jsonUsers); String hasvisible = jsonUsers.getString("hasvisible"); return new UserWapper(users, previousCursor, nextCursor, totalNumber, hasvisible); } catch (JsonException jsone) { throw new WeiboException(jsone); } }
Example #10
Source File: JSONNamedAssociationState.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public String nameOf( EntityReference entityReference ) { try { JsonObject references = getReferences(); for( String name : references.keySet() ) { if( entityReference.identity().toString().equals( references.getString( name ) ) ) { return name; } } return null; } catch( JsonException ex ) { throw new EntityStoreException( ex ); } }
Example #11
Source File: LogstashEventFormat.java From servicemix with Apache License 2.0 | 6 votes |
public String toString(PaxLoggingEvent event) { JsonObjectBuilder object = Json.createObjectBuilder(); try { object.add(MESSAGE, event.getMessage()); object.add(SOURCE, event.getLoggerName()); object.add(TIMESTAMP, TIMESTAMP_FORMAT.format(new Date(event.getTimeStamp()))); JsonObjectBuilder fields = Json.createObjectBuilder(); for (Object property : event.getProperties().entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) property; fields.add(entry.getKey(), entry.getValue().toString()); } object.add(FIELDS, fields); JsonArrayBuilder tags = Json.createArrayBuilder(); tags.add(event.getLevel().toString()); object.add(TAGS, tags); } catch (JsonException e) { // let's return a minimal, String-based message representation instead return "{ \"" + MESSAGE + "\" : " + event.getMessage() + "}"; } return object.build().toString(); }
Example #12
Source File: FIDO2RegistrationBean.java From fido2 with GNU Lesser General Public License v2.1 | 6 votes |
private void verifyRegistrationResponse(String registrationResponse){ try{ JsonObject registrationObject = skfsCommon.getJsonObjectFromString(registrationResponse); String[] requiredFields = { skfsConstants.JSON_KEY_ID, skfsConstants.JSON_KEY_RAW_ID, skfsConstants.JSON_KEY_REQUEST_TYPE, skfsConstants.JSON_KEY_SERVLET_INPUT_RESPONSE}; String[] requiredBase64UrlFields = { skfsConstants.JSON_KEY_ID, skfsConstants.JSON_KEY_RAW_ID }; verifyRequiredFieldsExist(registrationObject, requiredFields); verifyFieldsBase64Url(registrationObject, requiredBase64UrlFields); verifyAcceptedValue(registrationObject, skfsConstants.JSON_KEY_REQUEST_TYPE, new String[]{ "public-key" }); if(!registrationObject.getString(skfsConstants.JSON_KEY_ID).equals(registrationObject.getString(skfsConstants.JSON_KEY_RAW_ID))){ skfsLogger.log(skfsConstants.SKFE_LOGGER,Level.FINE, "FIDO-ERR-5011", "id does not match rawId"); throw new SKIllegalArgumentException("Json improperly formatted"); } } catch(JsonException ex){ skfsLogger.log(skfsConstants.SKFE_LOGGER,Level.FINE, "FIDO-ERR-5011", "Json improperly formatted"); throw new SKIllegalArgumentException("Json improperly formatted"); } }
Example #13
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public JsonObject removeProperty( MigrationContext context, JsonObject state, String name ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build(); JsonObject migratedState = jsonFactories .cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.propertyRemoved( state.getString( JSONKeys.IDENTITY ), name ); } return migratedState; } else { context.addFailure( "Remove property " + name ); return state; } }
Example #14
Source File: FHIRJsonProvider.java From FHIR with Apache License 2.0 | 6 votes |
@Override public void writeTo(JsonObject t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { log.entering(this.getClass().getName(), "writeTo"); try (JsonWriter writer = JSON_WRITER_FACTORY.createWriter(nonClosingOutputStream(entityStream))) { writer.writeObject(t); } catch (JsonException e) { // log the error but don't throw because that seems to block to original IOException from bubbling for some reason log.log(Level.WARNING, "an error occurred during resource serialization", e); if (RuntimeType.SERVER.equals(runtimeType)) { Response response = buildResponse( buildOperationOutcome(Collections.singletonList( buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.EXCEPTION, "FHIRProvider: " + e.getMessage(), null))), mediaType); throw new WebApplicationException(response); } } finally { log.exiting(this.getClass().getName(), "writeTo"); } }
Example #15
Source File: FHIRJsonProvider.java From FHIR with Apache License 2.0 | 6 votes |
@Override public JsonObject readFrom(Class<JsonObject> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { log.entering(this.getClass().getName(), "readFrom"); try (JsonReader reader = JSON_READER_FACTORY.createReader(nonClosingInputStream(entityStream))) { return reader.readObject(); } catch (JsonException e) { if (RuntimeType.SERVER.equals(runtimeType)) { String acceptHeader = httpHeaders.getFirst(HttpHeaders.ACCEPT); Response response = buildResponse( buildOperationOutcome(Collections.singletonList( buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.INVALID, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader)); throw new WebApplicationException(response); } else { throw new IOException("an error occurred during resource deserialization", e); } } finally { log.exiting(this.getClass().getName(), "readFrom"); } }
Example #16
Source File: FHIRJsonPatchProvider.java From FHIR with Apache License 2.0 | 6 votes |
@Override public void writeTo(JsonArray t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { log.entering(this.getClass().getName(), "writeTo"); try (JsonWriter writer = JSON_WRITER_FACTORY.createWriter(nonClosingOutputStream(entityStream))) { writer.writeArray(t); } catch (JsonException e) { // log the error but don't throw because that seems to block to original IOException from bubbling for some reason log.log(Level.WARNING, "an error occurred during JSON Patch serialization", e); if (RuntimeType.SERVER.equals(runtimeType)) { String acceptHeader = (String) httpHeaders.getFirst(HttpHeaders.ACCEPT); Response response = buildResponse( buildOperationOutcome(Collections.singletonList( buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.EXCEPTION, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader)); throw new WebApplicationException(response); } } finally { log.exiting(this.getClass().getName(), "writeTo"); } }
Example #17
Source File: FHIRJsonPatchProvider.java From FHIR with Apache License 2.0 | 6 votes |
@Override public JsonArray readFrom(Class<JsonArray> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { log.entering(this.getClass().getName(), "readFrom"); try (JsonReader reader = JSON_READER_FACTORY.createReader(nonClosingInputStream(entityStream))) { return reader.readArray(); } catch (JsonException e) { if (RuntimeType.SERVER.equals(runtimeType)) { String acceptHeader = httpHeaders.getFirst(HttpHeaders.ACCEPT); Response response = buildResponse( buildOperationOutcome(Collections.singletonList( buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.INVALID, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader)); throw new WebApplicationException(response); } else { throw new IOException("an error occurred during JSON Patch deserialization", e); } } finally { log.exiting(this.getClass().getName(), "readFrom"); } }
Example #18
Source File: JavaxJson.java From attic-polygene-java with Apache License 2.0 | 5 votes |
/** * Require a {@link JsonValue} to be a {@link JsonStructure}. * * @param json the JSON value * @return the JSON structure * @throws JsonException if it is not */ public static JsonStructure requireJsonStructure( JsonValue json ) { if( json.getValueType() != JsonValue.ValueType.OBJECT && json.getValueType() != JsonValue.ValueType.ARRAY ) { throw new JsonException( "Expected a JSON object or array but got " + json ); } return (JsonStructure) json; }
Example #19
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject addAssociation( MigrationContext context, JsonObject state, String name, String defaultReference ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( !valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilder( valueState ) .add( name, defaultReference ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.associationAdded( state.getString( JSONKeys.IDENTITY ), name, defaultReference ); } return migratedState; } else { context.addFailure( "Add association " + name + ", default:" + defaultReference ); return state; } }
Example #20
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject renameProperty( MigrationContext context, JsonObject state, String from, String to ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( from ) ) { JsonValue jsonValue = valueState.get( from ); valueState = jsonFactories.cloneBuilderExclude( valueState, from ) .add( to, jsonValue ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.propertyRenamed( state.getString( JSONKeys.IDENTITY ), from, to ); } return migratedState; } else { context.addFailure( "Rename property " + from + " to " + to ); return state; } }
Example #21
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject renameAssociation( MigrationContext context, JsonObject state, String from, String to ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( from ) ) { JsonValue jsonValue = valueState.get( from ); valueState = jsonFactories.cloneBuilderExclude( valueState, from ) .add( to, jsonValue ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.associationRenamed( state.getString( JSONKeys.IDENTITY ), from, to ); } return migratedState; } else { context.addFailure( "Rename association " + from + " to " + to ); return state; } }
Example #22
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject addManyAssociation( MigrationContext context, JsonObject state, String name, String... defaultReferences ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( !valueState.containsKey( name ) ) { JsonArrayBuilder refArrayBuilder = jsonFactories.builderFactory().createArrayBuilder(); for( String ref : defaultReferences ) { refArrayBuilder.add( ref ); } valueState = jsonFactories.cloneBuilder( valueState ) .add( name, refArrayBuilder.build() ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.manyAssociationAdded( state.getString( JSONKeys.IDENTITY ), name, defaultReferences ); } return migratedState; } else { context.addFailure( "Add many-association " + name + ", default:" + asList( defaultReferences ) ); return state; } }
Example #23
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject addProperty( MigrationContext context, JsonObject state, String name, Object defaultValue ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( !valueState.containsKey( name ) ) { valueState = jsonFactories.cloneBuilder( valueState ) .add( name, serialization.toJson( defaultValue ) ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.propertyAdded( state.getString( JSONKeys.IDENTITY ), name, defaultValue ); } return migratedState; } else { context.addFailure( "Add property " + name + ", default:" + defaultValue ); return state; } }
Example #24
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject renameManyAssociation( MigrationContext context, JsonObject state, String from, String to ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( from ) ) { JsonValue jsonValue = valueState.get( from ); valueState = jsonFactories.cloneBuilderExclude( valueState, from ) .add( to, jsonValue ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.manyAssociationRenamed( state.getString( JSONKeys.IDENTITY ), from, to ); } return migratedState; } else { context.addFailure( "Rename many-association " + from + " to " + to ); return state; } }
Example #25
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject addNamedAssociation( MigrationContext context, JsonObject state, String name, Map<String, String> defaultReferences ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( !valueState.containsKey( name ) ) { JsonObjectBuilder refBuilder = jsonFactories.builderFactory().createObjectBuilder(); for( Map.Entry<String, String> entry : defaultReferences.entrySet() ) { refBuilder.add( entry.getKey(), entry.getValue() ); } valueState = jsonFactories.cloneBuilder( valueState ) .add( name, refBuilder.build() ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.namedAssociationAdded( state.getString( JSONKeys.IDENTITY ), name, defaultReferences ); } return migratedState; } else { context.addFailure( "Add named-association " + name + ", default:" + defaultReferences ); return state; } }
Example #26
Source File: MigrationService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public JsonObject renameNamedAssociation( MigrationContext context, JsonObject state, String from, String to ) throws JsonException { JsonObject valueState = state.getJsonObject( JSONKeys.VALUE ); if( valueState.containsKey( from ) ) { JsonValue jsonValue = valueState.get( from ); valueState = jsonFactories.cloneBuilderExclude( valueState, from ) .add( to, jsonValue ) .build(); JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE ) .add( JSONKeys.VALUE, valueState ) .build(); context.markAsChanged(); for( MigrationEvents migrationEvent : migrationEvents ) { migrationEvent.namedAssociationRenamed( state.getString( JSONKeys.IDENTITY ), from, to ); } return migratedState; } else { context.addFailure( "Rename named-association " + from + " to " + to ); return state; } }
Example #27
Source File: JSONResponseReader.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public Object readResponse( Response response, Class<?> resultType ) { if( response.getEntity().getMediaType().equals( MediaType.APPLICATION_JSON ) ) { if( ValueComposite.class.isAssignableFrom( resultType ) ) { String jsonValue = response.getEntityAsText(); ValueCompositeType valueType = module.valueDescriptor( resultType.getName() ).valueType(); return jsonDeserializer.deserialize( module, valueType, jsonValue ); } else if( resultType.equals( Form.class ) ) { try( JsonReader reader = jsonFactories.readerFactory() .createReader( response.getEntity().getReader() ) ) { JsonObject jsonObject = reader.readObject(); Form form = new Form(); jsonObject.forEach( ( key, value ) -> { String valueString = value.getValueType() == JsonValue.ValueType.STRING ? ( (JsonString) value ).getString() : value.toString(); form.set( key, valueString ); } ); return form; } catch( IOException | JsonException e ) { throw new ResourceException( e ); } } } return null; }
Example #28
Source File: JavaxJson.java From attic-polygene-java with Apache License 2.0 | 5 votes |
/** * Require a {@link JsonValue} to be a {@link JsonObject}. * * @param json the JSON value * @return the JSON object * @throws JsonException if it is not */ public static JsonObject requireJsonObject( JsonValue json ) { if( json.getValueType() != JsonValue.ValueType.OBJECT ) { throw new JsonException( "Expected a JSON object but got " + json ); } return (JsonObject) json; }
Example #29
Source File: JavaxJson.java From attic-polygene-java with Apache License 2.0 | 5 votes |
/** * Require a {@link JsonValue} to be a {@link JsonArray}. * * @param json the JSON value * @return the JSON array * @throws JsonException if it is not */ public static JsonArray requireJsonArray( JsonValue json ) { if( json.getValueType() != JsonValue.ValueType.ARRAY ) { throw new JsonException( "Expected a JSON array but got " + json ); } return (JsonArray) json; }
Example #30
Source File: JSONManyAssociationState.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public Iterator<EntityReference> iterator() { return new Iterator<EntityReference>() { private int idx = 0; @Override public boolean hasNext() { return idx < getReferences().size(); } @Override public EntityReference next() { try { EntityReference ref = EntityReference.parseEntityReference( getReferences().getString( idx ) ); idx++; return ref; } catch( JsonException e ) { throw new NoSuchElementException(); } } @Override public void remove() { throw new UnsupportedOperationException( "remove() is not supported on ManyAssociation iterators." ); } }; }