public static <T> T readValue(InputStream bytes, Class<T> type) throws IOException { return readValue(bytes, type, false); }
public static JsonNode convertToJsonNode(Object object) throws IOException { if (object instanceof JsonNode) { return (JsonNode) object; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); buffer.write(JsonSerialization.writeValueAsBytes(object)); return MAPPER.readValue(buffer.toByteArray(), JsonNode.class); }
private void outputResult(Object result) throws IOException { if (outputClient) { if (compressed) { printOut(JsonSerialization.writeValueAsString(result)); } else { printOut(JsonSerialization.writeValueAsPrettyString(result)); } } }
/** * Creates an {@link ObjectNode} based on the given {@code pojo}, copying all its properties to the resulting {@link ObjectNode}. * * @param pojo a pojo which properties will be populates into the resulting a {@link ObjectNode} * @return a {@link ObjectNode} with all the properties from the given pojo * @throws IOException if the resulting a {@link ObjectNode} can not be created */ public static ObjectNode createObjectNode(Object pojo) throws IOException { if (pojo == null) { throw new IllegalArgumentException("Pojo can not be null."); } ObjectNode objectNode = createObjectNode(); JsonParser jsonParser = mapper.getJsonFactory().createJsonParser(writeValueAsBytes(pojo)); JsonNode jsonNode = jsonParser.readValueAsTree(); if (!jsonNode.isObject()) { throw new RuntimeException("JsonNode [" + jsonNode + "] is not a object."); } objectNode.putAll((ObjectNode) jsonNode); return objectNode; }
byte[] buf = new byte[(int) size]; file.readFully(buf); config = JsonSerialization.readValue(new ByteArrayInputStream(buf), ConfigData.class); byte [] content = JsonSerialization.writeValueAsPrettyString(config).getBytes("utf-8"); file.seek(0); file.write(content);
public void addClientScopeRolesForApplication(String authToken, String realmName, String clientApp, String appName, List<RoleRepresentation> roles) throws Exception { HttpPost post = new HttpPost(clientScopeForApplicationsEndpoint(realmName, clientApp, appName)); addAuthzHeader(post, authToken); post.setEntity(new StringEntity(JsonSerialization.writeValueAsString(roles), ContentType.create(MediaType.JSON.toString(), "UTF-8"))); exec(post, 204, "Unable to add roles to client application " + clientApp, new VoidHandler()); }
@Override public String toString() { try { return JsonSerialization.writeValueAsPrettyString(this); } catch (IOException e) { return super.toString() + " - Error: " + e.toString(); } } }
byte[] buf = new byte[(int) size]; file.readFully(buf); config = JsonSerialization.readValue(new ByteArrayInputStream(buf), ConfigData.class); byte [] content = JsonSerialization.writeValueAsPrettyString(config).getBytes("utf-8"); file.seek(0); file.write(content);
@Override public void onExport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorization) { ClientPolicyRepresentation userRep = toRepresentation(policy, authorization); Map<String, String> config = new HashMap<>(); try { RealmModel realm = authorization.getRealm(); config.put("clients", JsonSerialization.writeValueAsString(userRep.getClients().stream().map(id -> realm.getClientById(id).getClientId()).collect(Collectors.toList()))); } catch (IOException cause) { throw new RuntimeException("Failed to export user policy [" + policy.getName() + "]", cause); } representation.setConfig(config); }
@Override public String toString() { try { return JsonSerialization.writeValueAsPrettyString(this); } catch (IOException e) { return super.toString() + " - Error: " + e.toString(); } }
private HashSet<GroupPolicyRepresentation.GroupDefinition> getGroupsDefinition(Map<String, String> config) throws IOException { return new HashSet<>(Arrays.asList(JsonSerialization.readValue(config.get("groups"), GroupPolicyRepresentation.GroupDefinition[].class))); } }
ClientRepresentation client = JsonSerialization.readValue(json, ClientRepresentation.class); result = client; OIDCClientRepresentation client = JsonSerialization.readValue(json, OIDCClientRepresentation.class); result = client; result = JsonSerialization.readValue(json, AdapterConfig.class); break; json = JsonSerialization.writeValueAsPrettyString(result);
@Override public void onExport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorizationProvider) { UserPolicyRepresentation userRep = toRepresentation(policy, authorizationProvider); Map<String, String> config = new HashMap<>(); try { UserProvider userProvider = authorizationProvider.getKeycloakSession().users(); RealmModel realm = authorizationProvider.getRealm(); config.put("users", JsonSerialization.writeValueAsString(userRep.getUsers().stream().map(id -> userProvider.getUserById(id, realm).getUsername()).collect(Collectors.toList()))); } catch (IOException cause) { throw new RuntimeException("Failed to export user policy [" + policy.getName() + "]", cause); } representation.setConfig(config); }
public String getBase64Header() throws IOException { if (base64Header == null && header != null) { byte[] contentBytes = JsonSerialization.writeValueAsBytes(header); base64Header = Base64Url.encode(contentBytes); } return base64Header; }
private void outputResult(String clientId, Object result) throws IOException { if (returnClientId) { printOut(clientId); } else if (outputClient) { if (compressed) { printOut(JsonSerialization.writeValueAsString(result)); } else { printOut(JsonSerialization.writeValueAsPrettyString(result)); } } else { printErr("Registered new client with client_id '" + clientId + "'"); } }
@Override public String toString() { try { return JsonSerialization.writeValueAsPrettyString(this); } catch (IOException e) { return super.toString() + " - Error: " + e.toString(); } }
private <T> T parseToken(String encoded, Class<T> clazz) throws IOException { if (encoded == null) return null; String[] parts = encoded.split("\\."); if (parts.length < 2 || parts.length > 3) throw new IllegalArgumentException("Parsing error"); byte[] bytes = Base64Url.decode(parts[1]); return JsonSerialization.readValue(bytes, clazz); }
public PersistentUserSessionModel getUpdatedModel() { try { String updatedData = JsonSerialization.writeValueAsString(getData()); this.model.setData(updatedData); } catch (IOException ioe) { throw new ModelException(ioe); } return this.model; }
public EncodingBuilder jsonContent(Object object) { try { this.contentBytes = JsonSerialization.writeValueAsBytes(object); } catch (IOException e) { throw new RuntimeException(e); } return new EncodingBuilder(); }
@Override public String toString() { try { return JsonSerialization.writeValueAsPrettyString(this); } catch (IOException e) { return super.toString() + " - Error: " + e.toString(); } } }