Skip to content

For Quantity class adding a no-arg constructor#930

Closed
ZP-AlwaysWin wants to merge 1 commit intokubernetes-client:masterfrom
ZP-AlwaysWin:master
Closed

For Quantity class adding a no-arg constructor#930
ZP-AlwaysWin wants to merge 1 commit intokubernetes-client:masterfrom
ZP-AlwaysWin:master

Conversation

@ZP-AlwaysWin
Copy link
Copy Markdown

@ZP-AlwaysWin ZP-AlwaysWin commented Apr 23, 2020

I want to use reflection to parse the content in Yaml into the Quantity class, but I always get an error, so I want to add a parameterless constructor to this class

demo.yaml

limits:
  cpu:
    number: 0.005
    format: DECIMAL_SI

DemoYaml.java

package com.example.springdemo.utils;

import java.io.FileReader;

import com.esotericsoftware.yamlbeans.YamlReader;

import io.kubernetes.client.custom.Quantity;
import io.kubernetes.client.models.V1ResourceRequirements;


public class DemoYaml {
    public void transYaml() throws Exception{

        YamlReader reader = new YamlReader(new FileReader("demo.yaml"));
        V1ResourceRequirements demo = reader.read(V1ResourceRequirements.class);
        System.out.println(demo);
    }
    public static void main(String[] args) {

        Quantity x = new Quantity("5m");
        System.out.println(x);
        DemoYaml demoYaml = new DemoYaml();
        try {
            demoYaml.transYaml();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

exception

Caused by: java.lang.reflect.InvocationTargetException: Unable to find a no-arg constructor for class: io.kubernetes.client.custom.Quantity

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 23, 2020
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ZP-AlwaysWin
To complete the pull request process, please assign brendandburns
You can assign the PR to them by writing /assign @brendandburns in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 23, 2020
@ZP-AlwaysWin
Copy link
Copy Markdown
Author

/assign @brendandburns

Copy link
Copy Markdown
Member

@yue9944882 yue9944882 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz use io.kubernetes.client.util.Yaml as the decoder instead of com.esotericsoftware.yamlbeans.YamlReader. the former has a set of custom serializers for kubernetes specific types

@ZP-AlwaysWin
Copy link
Copy Markdown
Author

plz use io.kubernetes.client.util.Yaml as the decoder instead of com.esotericsoftware.yamlbeans.YamlReader. the former has a set of custom serializers for kubernetes specific types

This doesn't seem to solve my problem. How can I convert V1Container

@ZP-AlwaysWin ZP-AlwaysWin requested a review from yue9944882 April 23, 2020 06:22
@brendandburns
Copy link
Copy Markdown
Contributor

@ZP-AlwaysWin
Copy link
Copy Markdown
Author

OK, that solves my problem perfectly。
Thanks very much @brendandburns @yue9944882

@brendandburns
Copy link
Copy Markdown
Contributor

Closing since the issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants