/** * Unmarshals a stream. * @param is The {@link InputStream}. * @param <T> The target type. * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is) throws KubernetesClientException { return unmarshal(is, JSON_MAPPER); }
/** * Unmarshals a stream optionally performing placeholder substitution to the stream. * @param is The {@link InputStream}. * @param parameters A {@link Map} with parameters for placeholder substitution. * @param <T> The target type. * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is, Map<String, String> parameters) throws KubernetesClientException { String specFile = readSpecFileFromInputStream(is); if (containsMultipleDocuments(specFile)) { return (T) getKubernetesResourceList(parameters, specFile); } return unmarshal(new ByteArrayInputStream(specFile.getBytes()), JSON_MAPPER, parameters); }
private static List<KubernetesResource> getKubernetesResourceList(Map<String, String> parameters, String specFile) { List<KubernetesResource> documentList = new ArrayList<>(); String[] documents = splitSpecFile(specFile); for (String document : documents) { if (validate(document)) { ByteArrayInputStream documentInputStream = new ByteArrayInputStream(document.getBytes()); Object resource = Serialization.unmarshal(documentInputStream, parameters); documentList.add((KubernetesResource) resource); } } return documentList; }
private static boolean containsMultipleDocuments(String specFile) { String[] documents = splitSpecFile(specFile); int nValidDocuments = 0; for(String document : documents) { if(validate(document)) nValidDocuments++; } return nValidDocuments > 1; }
if (request.body() != null && !request.method().equalsIgnoreCase(PATCH)) { request.body().writeTo(buffer); Object object = Serialization.unmarshal(buffer.inputStream()); if (object instanceof HasMetadata) { HasMetadata h = (HasMetadata) object; h.setApiVersion(target.group + "/" + target.version); newRequest = newRequest.method(request.method(), RequestBody.create(OperationSupport.JSON, Serialization.asJson(h)));
@Test public void shouldInstantiateClientUsingSerializeDeserialize() throws MalformedURLException { DefaultOpenShiftClient original = new DefaultOpenShiftClient(); String json = Serialization.asJson(original.getConfiguration()); DefaultOpenShiftClient copy = DefaultOpenShiftClient.fromConfig(json); Assert.assertEquals(original.getConfiguration().getMasterUrl(), copy.getConfiguration().getMasterUrl()); Assert.assertEquals(original.getConfiguration().getOauthToken(), copy.getConfiguration().getOauthToken()); Assert.assertEquals(original.getConfiguration().getNamespace(), copy.getConfiguration().getNamespace()); Assert.assertEquals(original.getConfiguration().getUsername(), copy.getConfiguration().getUsername()); Assert.assertEquals(original.getConfiguration().getPassword(), copy.getConfiguration().getPassword()); } }
public KubernetesCrudDispatcher(AttributeExtractor attributeExtractor, ResponseComposer responseComposer) { super(new Context(Serialization.jsonMapper()), attributeExtractor, responseComposer); }
@Test public void shouldInstantiateClientUsingSerializeDeserialize() throws MalformedURLException { DefaultKubernetesClient original = new DefaultKubernetesClient(); String json = Serialization.asJson(original.getConfiguration()); DefaultKubernetesClient copy = DefaultKubernetesClient.fromConfig(json); Assert.assertEquals(original.getConfiguration().getMasterUrl(), copy.getConfiguration().getMasterUrl()); Assert.assertEquals(original.getConfiguration().getOauthToken(), copy.getConfiguration().getOauthToken()); Assert.assertEquals(original.getConfiguration().getNamespace(), copy.getConfiguration().getNamespace()); Assert.assertEquals(original.getConfiguration().getUsername(), copy.getConfiguration().getUsername()); Assert.assertEquals(original.getConfiguration().getPassword(), copy.getConfiguration().getPassword()); }
public KubernetesCrudDispatcher(AttributeExtractor attributeExtractor, ResponseComposer responseComposer) { super(new Context(Serialization.jsonMapper()), attributeExtractor, responseComposer); }
protected static <T> T unmarshal(InputStream is, final Class<T> type) throws KubernetesClientException { return Serialization.unmarshal(is, type); }
protected static <T> T unmarshal(InputStream is, TypeReference<T> type) throws KubernetesClientException { return Serialization.unmarshal(is, type); }
protected static <T> T unmarshal(InputStream is) throws KubernetesClientException { return Serialization.unmarshal(is); }
/** * Unmarshals an {@link InputStream} optionally performing placeholder substitution to the stream. * @param is The {@link InputStream}. * @param type The type. * @param parameters A {@link Map} with parameters for placeholder substitution. * @param <T> * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is, final Class<T> type, Map<String, String> parameters) throws KubernetesClientException { return unmarshal(is, new TypeReference<T>() { @Override public Type getType() { return type; } }, parameters); }
/** * Unmarshals a {@link String} * @param str The {@link String}. * @param type The target type. * @param <T> * @return * @throws KubernetesClientException */ public static <T> T unmarshal(String str, final Class<T> type) throws KubernetesClientException { return unmarshal(str, type, Collections.<String, String>emptyMap()); }
/** * Unmarshals an {@link InputStream}. * @param is The {@link InputStream}. * @param type The {@link TypeReference}. * @param <T> * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is, TypeReference<T> type) throws KubernetesClientException { return unmarshal(is, type, Collections.<String, String>emptyMap()); }
/** * Unmarshals a stream. * @param is The {@link InputStream}. * @param mapper The {@link ObjectMapper} to use. * @param <T> The target type. * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is, ObjectMapper mapper) { return unmarshal(is, mapper, Collections.<String, String>emptyMap()); }
/** * Unmarshals an {@link InputStream}. * @param is The {@link InputStream}. * @param type The type. * @param <T> * @return * @throws KubernetesClientException */ public static <T> T unmarshal(InputStream is, final Class<T> type) throws KubernetesClientException { return unmarshal(is, type, Collections.<String, String>emptyMap()); }
private static HasMetadata toKubernetesResource(String s) { try (InputStream stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8.name()))) { return Serialization.unmarshal(stream); } catch (Exception e) { return null; } } }
public static DefaultKubernetesClient fromConfig(InputStream is) { return new DefaultKubernetesClient(Serialization.unmarshal(is, Config.class)); }
public static DefaultOpenShiftClient fromConfig(InputStream is) { return new DefaultOpenShiftClient(Serialization.unmarshal(is, OpenShiftConfig.class)); }