Skip to content

Commit 0814be7

Browse files
committed
Change json logic
1 parent 90ed43a commit 0814be7

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

CedarJava/src/main/java/com/cedarpolicy/model/entity/Entity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ public JsonNode toJsonValue() throws NullPointerException, InternalException, Js
109109
* @throws JsonProcessingException if the Entity JSON is unable to be processed
110110
* @throws IOException if the Entity is unable to be written to the file
111111
*/
112-
public void writeToJson(File file) throws NullPointerException, InternalException, JsonProcessingException, IOException {
113-
ObjectWriter writer = OBJECT_MAPPER.writer();
114-
JsonNode entityJson = this.toJsonValue();
115-
writer.writeValue(file, entityJson);
116-
}
112+
public void writeToJson(File file) throws NullPointerException, InternalException, JsonProcessingException, IOException {
113+
ObjectWriter writer = OBJECT_MAPPER.writer();
114+
JsonNode entityJson = this.toJsonValue();
115+
writer.writeValue(file, entityJson);
116+
}
117117

118118
/**
119119
* Get the value for the given attribute, or null if not present.

CedarJavaFFI/src/interface.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,21 @@ fn from_json_internal<'a>(
462462
}
463463

464464
#[jni_fn("com.cedarpolicy.model.entity.Entity")]
465-
pub fn toJsonEntityJni<'a>(mut env: JNIEnv<'a>, _: JClass, entity: JEntity<'a>) -> jvalue {
466-
match to_json_entity_internal(&mut env, entity) {
465+
pub fn toJsonEntityJni<'a>(mut env: JNIEnv<'a>, _: JClass, obj: JObject<'a>) -> jvalue {
466+
match to_json_entity_internal(&mut env, obj) {
467467
Ok(v) => v.as_jni(),
468468
Err(e) => jni_failed(&mut env, e.as_ref()),
469469
}
470470
}
471471

472-
fn to_json_entity_internal<'a>(
473-
env: &mut JNIEnv<'a>,
474-
java_entity: JEntity<'a>,
475-
) -> Result<JValueOwned<'a>> {
476-
if java_entity.as_ref().is_null() {
472+
fn to_json_entity_internal<'a>(env: &mut JNIEnv<'a>, obj: JObject<'a>) -> Result<JValueOwned<'a>> {
473+
if obj.is_null() {
477474
raise_npe(env)
478475
} else {
476+
let java_entity = JEntity::cast(env, obj)?;
479477
let entity = java_entity.to_entity(env)?;
480-
let entity_json = serde_json::to_string(&entity.to_json_value()?)?;
481-
Ok(JValueGen::Object(env.new_string(&entity_json)?.into()))
478+
let entity_json = &entity.to_json_string()?;
479+
Ok(JValueGen::Object(env.new_string(entity_json)?.into()))
482480
}
483481
}
484482

0 commit comments

Comments
 (0)