UcasRichard / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

Add type safe API for load methods #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
just a minor proposal.

e.g. for:
    public Object load(String yaml) {
        return load(new StringReader(yaml));
    }

add one more API of:
    public <T> T load(String yaml, Class<T> returnType){
        return (T)load(yaml);
    }

And the user may use:
  User user = new Yaml().load("--- !!a.b.User", User.class);
instead of:
  User user = (User) new Yaml().load("--- !!a.b.User");

it's quite "trendy" to use typesafe API. e.g. in spring, it supports 
getBean("peter", User.class); in guice, a provider get() method is typed with 
generic.

Original issue reported on code.google.com by mingfai...@gmail.com on 9 Sep 2010 at 11:45

GoogleCodeExporter commented 9 years ago
it's a nice-to-have. I'm submitting the patch mainly because I'm touching the 
code anyway. :-)

Original comment by mingfai...@gmail.com on 9 Sep 2010 at 11:47

Attachments:

GoogleCodeExporter commented 9 years ago
Why is it better then JavaBeanLoader ? (which also can provide some 
configuration)

Original comment by py4fun@gmail.com on 10 Sep 2010 at 8:45

GoogleCodeExporter commented 9 years ago
sorry, i didn't know about the JavaBeanloader b4. that's exactly i'm looking 
for. And that's a better way that my suggestion (which is copy from Spring and 
actually i think the 2nd class parameter is just for IoC bean lookup and it is 
not relevant to SnakeYaml) please close the issue. 

Original comment by mingfai...@gmail.com on 26 Sep 2010 at 3:47

GoogleCodeExporter commented 9 years ago

Original comment by py4fun@gmail.com on 27 Sep 2010 at 7:34