Parameter resolving /converter for dynamically registered commands












1















I am working on a Spring Shell 2 CLI and i am trying to generate commands at runtime from a defined interface through reflection.
Update: The implementation of the interface is also generated at runtime.

I am using the ConfigurableCommandRegistry and MethodTarget to register my command.

Is there a way to setup/register converters at runtime for the parameters of the method that is passed to MethodTarget?

What would be the best approach to do this?



I am pretty new to java and spring and i am not sure if this is possible at all. Keep that in mind and pls dont kill me :)

The Extending Spring Shell of the docs is missing (incomplete?)

I already checked the Spring shell project but could not find something to work with.

Maybe this is possible with Parameter Resolving?
or generating Converters at runtime with FormatterRegistrar?



Registering commands as followed



MethodTarget command = new MethodTarget(method, client, new Command.Help(description, group), availabilityIndicator);
registry.register(commandName, command);


method and method paramters, client, description, group is retrieved via reflection from the interface.



I would like to generate a command at runtime from an interface




public interface MessagingManagement {
@ShellMethod(...)
public void createPerson(@ShellOption(...)Person person);
}


which is callable with following parameters
create-person --person name age (or more paramters)



In short i would like to generate converters for paramaters that are complex objects and flatten them.

Nested objects are ignored










share|improve this question





























    1















    I am working on a Spring Shell 2 CLI and i am trying to generate commands at runtime from a defined interface through reflection.
    Update: The implementation of the interface is also generated at runtime.

    I am using the ConfigurableCommandRegistry and MethodTarget to register my command.

    Is there a way to setup/register converters at runtime for the parameters of the method that is passed to MethodTarget?

    What would be the best approach to do this?



    I am pretty new to java and spring and i am not sure if this is possible at all. Keep that in mind and pls dont kill me :)

    The Extending Spring Shell of the docs is missing (incomplete?)

    I already checked the Spring shell project but could not find something to work with.

    Maybe this is possible with Parameter Resolving?
    or generating Converters at runtime with FormatterRegistrar?



    Registering commands as followed



    MethodTarget command = new MethodTarget(method, client, new Command.Help(description, group), availabilityIndicator);
    registry.register(commandName, command);


    method and method paramters, client, description, group is retrieved via reflection from the interface.



    I would like to generate a command at runtime from an interface




    public interface MessagingManagement {
    @ShellMethod(...)
    public void createPerson(@ShellOption(...)Person person);
    }


    which is callable with following parameters
    create-person --person name age (or more paramters)



    In short i would like to generate converters for paramaters that are complex objects and flatten them.

    Nested objects are ignored










    share|improve this question



























      1












      1








      1








      I am working on a Spring Shell 2 CLI and i am trying to generate commands at runtime from a defined interface through reflection.
      Update: The implementation of the interface is also generated at runtime.

      I am using the ConfigurableCommandRegistry and MethodTarget to register my command.

      Is there a way to setup/register converters at runtime for the parameters of the method that is passed to MethodTarget?

      What would be the best approach to do this?



      I am pretty new to java and spring and i am not sure if this is possible at all. Keep that in mind and pls dont kill me :)

      The Extending Spring Shell of the docs is missing (incomplete?)

      I already checked the Spring shell project but could not find something to work with.

      Maybe this is possible with Parameter Resolving?
      or generating Converters at runtime with FormatterRegistrar?



      Registering commands as followed



      MethodTarget command = new MethodTarget(method, client, new Command.Help(description, group), availabilityIndicator);
      registry.register(commandName, command);


      method and method paramters, client, description, group is retrieved via reflection from the interface.



      I would like to generate a command at runtime from an interface




      public interface MessagingManagement {
      @ShellMethod(...)
      public void createPerson(@ShellOption(...)Person person);
      }


      which is callable with following parameters
      create-person --person name age (or more paramters)



      In short i would like to generate converters for paramaters that are complex objects and flatten them.

      Nested objects are ignored










      share|improve this question
















      I am working on a Spring Shell 2 CLI and i am trying to generate commands at runtime from a defined interface through reflection.
      Update: The implementation of the interface is also generated at runtime.

      I am using the ConfigurableCommandRegistry and MethodTarget to register my command.

      Is there a way to setup/register converters at runtime for the parameters of the method that is passed to MethodTarget?

      What would be the best approach to do this?



      I am pretty new to java and spring and i am not sure if this is possible at all. Keep that in mind and pls dont kill me :)

      The Extending Spring Shell of the docs is missing (incomplete?)

      I already checked the Spring shell project but could not find something to work with.

      Maybe this is possible with Parameter Resolving?
      or generating Converters at runtime with FormatterRegistrar?



      Registering commands as followed



      MethodTarget command = new MethodTarget(method, client, new Command.Help(description, group), availabilityIndicator);
      registry.register(commandName, command);


      method and method paramters, client, description, group is retrieved via reflection from the interface.



      I would like to generate a command at runtime from an interface




      public interface MessagingManagement {
      @ShellMethod(...)
      public void createPerson(@ShellOption(...)Person person);
      }


      which is callable with following parameters
      create-person --person name age (or more paramters)



      In short i would like to generate converters for paramaters that are complex objects and flatten them.

      Nested objects are ignored







      java spring spring-boot reflection spring-shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 22 at 10:01







      Adem Vural

















      asked Jan 20 at 9:21









      Adem VuralAdem Vural

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Any bean that is a Converter<String, Person> should work and be picked up by Spring Shell automatically. Have a look at ConversionExample in the samples.



          That being said, why are you saying you want to register everything dynamically? Spring Shell is meant to pick up code annotated with its special annotations (like eg @ShellMethod). While it should be possible to dynamically do the work that the standard registrars do when seeing those annotations, it seems from your examples that you're OK with annotating your code with @ShellMethod already? So why not let Spring Shell do the discovery and registration for you?



          To put it another way: why are you annotating the interface rather that the implementation method? If you did so, you wouldn't have to deal with MethodTarget etc, this is all done automatically for you by Spring Shell.



          Hopefully this clarifies things and turns out to be the simplest solution






          share|improve this answer
























          • Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

            – Adem Vural
            Jan 22 at 11:09











          • How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

            – ebottard
            Jan 23 at 13:12











          • When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

            – Adem Vural
            Feb 1 at 8:22













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275060%2fparameter-resolving-converter-for-dynamically-registered-commands%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Any bean that is a Converter<String, Person> should work and be picked up by Spring Shell automatically. Have a look at ConversionExample in the samples.



          That being said, why are you saying you want to register everything dynamically? Spring Shell is meant to pick up code annotated with its special annotations (like eg @ShellMethod). While it should be possible to dynamically do the work that the standard registrars do when seeing those annotations, it seems from your examples that you're OK with annotating your code with @ShellMethod already? So why not let Spring Shell do the discovery and registration for you?



          To put it another way: why are you annotating the interface rather that the implementation method? If you did so, you wouldn't have to deal with MethodTarget etc, this is all done automatically for you by Spring Shell.



          Hopefully this clarifies things and turns out to be the simplest solution






          share|improve this answer
























          • Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

            – Adem Vural
            Jan 22 at 11:09











          • How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

            – ebottard
            Jan 23 at 13:12











          • When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

            – Adem Vural
            Feb 1 at 8:22


















          0














          Any bean that is a Converter<String, Person> should work and be picked up by Spring Shell automatically. Have a look at ConversionExample in the samples.



          That being said, why are you saying you want to register everything dynamically? Spring Shell is meant to pick up code annotated with its special annotations (like eg @ShellMethod). While it should be possible to dynamically do the work that the standard registrars do when seeing those annotations, it seems from your examples that you're OK with annotating your code with @ShellMethod already? So why not let Spring Shell do the discovery and registration for you?



          To put it another way: why are you annotating the interface rather that the implementation method? If you did so, you wouldn't have to deal with MethodTarget etc, this is all done automatically for you by Spring Shell.



          Hopefully this clarifies things and turns out to be the simplest solution






          share|improve this answer
























          • Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

            – Adem Vural
            Jan 22 at 11:09











          • How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

            – ebottard
            Jan 23 at 13:12











          • When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

            – Adem Vural
            Feb 1 at 8:22
















          0












          0








          0







          Any bean that is a Converter<String, Person> should work and be picked up by Spring Shell automatically. Have a look at ConversionExample in the samples.



          That being said, why are you saying you want to register everything dynamically? Spring Shell is meant to pick up code annotated with its special annotations (like eg @ShellMethod). While it should be possible to dynamically do the work that the standard registrars do when seeing those annotations, it seems from your examples that you're OK with annotating your code with @ShellMethod already? So why not let Spring Shell do the discovery and registration for you?



          To put it another way: why are you annotating the interface rather that the implementation method? If you did so, you wouldn't have to deal with MethodTarget etc, this is all done automatically for you by Spring Shell.



          Hopefully this clarifies things and turns out to be the simplest solution






          share|improve this answer













          Any bean that is a Converter<String, Person> should work and be picked up by Spring Shell automatically. Have a look at ConversionExample in the samples.



          That being said, why are you saying you want to register everything dynamically? Spring Shell is meant to pick up code annotated with its special annotations (like eg @ShellMethod). While it should be possible to dynamically do the work that the standard registrars do when seeing those annotations, it seems from your examples that you're OK with annotating your code with @ShellMethod already? So why not let Spring Shell do the discovery and registration for you?



          To put it another way: why are you annotating the interface rather that the implementation method? If you did so, you wouldn't have to deal with MethodTarget etc, this is all done automatically for you by Spring Shell.



          Hopefully this clarifies things and turns out to be the simplest solution







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 21 at 11:41









          ebottardebottard

          1,7672914




          1,7672914













          • Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

            – Adem Vural
            Jan 22 at 11:09











          • How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

            – ebottard
            Jan 23 at 13:12











          • When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

            – Adem Vural
            Feb 1 at 8:22





















          • Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

            – Adem Vural
            Jan 22 at 11:09











          • How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

            – ebottard
            Jan 23 at 13:12











          • When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

            – Adem Vural
            Feb 1 at 8:22



















          Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

          – Adem Vural
          Jan 22 at 11:09





          Thank you for the answers. Actually the implemenation of the service is generated at runtime. I forgott to mention this importent information in my initial question, sry!

          – Adem Vural
          Jan 22 at 11:09













          How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

          – ebottard
          Jan 23 at 13:12





          How is it generated? Can the generated implementation bear the Spring Shell annotations (instead of the interface)?

          – ebottard
          Jan 23 at 13:12













          When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

          – Adem Vural
          Feb 1 at 8:22







          When a Converter e.g. Converter<String, Person> is used e.g. public class Person { private String name; private String addresse; private int age; } I loose the detailed information of the pojo, including the available parameters, their type wether they are mandatory or not, etc. To put it different. When i use a converter is it possible to pass single parameters by name like:"add-person --name foo --address bar --age 42" or do i have to input the person parameters e.g. as json "add-person {name:foo, address:bar, age:42 }" Without any input help for the single parameters of the pojo?

          – Adem Vural
          Feb 1 at 8:22






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275060%2fparameter-resolving-converter-for-dynamically-registered-commands%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage