| 1124 | } |
| 1125 | |
| 1126 | pub fn get_json_schema_internal<'a>( |
| 1127 | env: &mut JNIEnv<'a>, |
| 1128 | cedar_schema_jstr: JString<'a>, |
| 1129 | ) -> Result<JValueOwned<'a>> { |
| 1130 | let schema_jstr = env.get_string(&cedar_schema_jstr)?; |
| 1131 | let schema_str = schema_jstr.to_str()?; |
| 1132 | let cedar_schema_str = FFISchema::Cedar(schema_str.into()); |
| 1133 | let json_format = schema_to_json(cedar_schema_str); |
| 1134 | |
| 1135 | match json_format { |
| 1136 | SchemaToJsonAnswer::Success { json, warnings: _ } => { |
| 1137 | let json_pretty = serde_json::to_string_pretty(&json)?; |
| 1138 | let jstr = env.new_string(&json_pretty)?; |
| 1139 | Ok(JValueGen::Object(JObject::from(jstr)).into()) |
| 1140 | } |
| 1141 | SchemaToJsonAnswer::Failure { errors } => { |
| 1142 | let joined_errors = errors |
| 1143 | .iter() |
| 1144 | .map(|e| e.message.clone()) |
| 1145 | .collect::<Vec<_>>() |
| 1146 | .join("; "); |
| 1147 | Err(joined_errors.into()) |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | #[cfg(test)] |
| 1153 | pub(crate) mod jvm_based_tests { |