Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deserializing nested JSON documents (using google gson) #144

Closed
wants to merge 1 commit into from

Conversation

ketan
Copy link

@ketan ketan commented Oct 1, 2015

For developers not wanting to use json, and to keep the dependency foot-print
at a minimum, the gson dependency is set to "provided".

The LoadersManager will check if Google's Gson parser is available on
path before attempting to register the JSON parser. (I'm happy to change this
behavior if you feel there's a better way to do this)

Usage -

{
  "server": {
    "http": {
      "port": 80,
      "hostname": "localhost"
    },
    "ssh": {
      "port": 22,
      "address": "127.0.0.1",
      "alive": {
        "interval": 60
      },
      "user": "admin"
    },
    "admins": ["bob", "alice"]
  }
}
@Config.Sources({"classpath:org/aeonbits/owner/server.test.json"})
public static interface ServerConfig extends Config, Accessible {

    @Key("server.http.port")
    int httpPort();

    @Key("server.http.hostname")
    String httpHostname();

    @Key("server.ssh.port")
    int sshPort();

    @Key("server.ssh.address")
    String sshAddress();

    @Key("server.ssh.alive.interval")
    int aliveInterval();

    @Key("server.ssh.user")
    String sshUser();

    @Key("server.admins")
    List<String> admins();
}

@ketan
Copy link
Author

ketan commented Oct 1, 2015

Arrays containing JSON objects will not be parsed (to keep the code simple). For e.g. this is not valid –

{
  "server" : {
    "admins": [
        {"john": { "last_name": "doe"}},
        {"ravi": { "last_name": "kumar"}},
    ]
  }
}

However this is legit –

{
  "server" : {
    "admins": ["john", "ravi"]
  }
}

@ketan
Copy link
Author

ketan commented Oct 31, 2015

Hi,

I've not seen any activity or interest in this PR (or commits to the repository). Anyone home?

@lviggiano
Copy link
Collaborator

Hi everyone , I am having health problems so at the moment I am not
monitoring the project actively, but I hope to be back as soon as possible.

Since some years I am affected by cancer and in these months I am following
chemio theraphy. Unfortunately my response is not very good in therms of
strength, and I have limited internet an computer access. But doctors say I
should heal and get back to work soon. And I hope they are right. I
apologize with you all,and thank everyone for understanding.

Cheers
Luigi
Il 31 ott 2015 18:16, "Ketan Padegaonkar" [email protected] ha
scritto:

Hi,

I've not seen any activity or interest in this PR (or commits to the
repository). Anyone home?


Reply to this email directly or view it on GitHub
#144 (comment).

@ketan
Copy link
Author

ketan commented Dec 16, 2015

Hi —

I'm sorry to hear that, and I hope you feel better.

I just realized that I'd submitted the pull request against the main project, when a better place was the owner-extras maven project. I've updated the pull request to reflect that.

For developers not wanting to use json, and to keep the dependency foot-print
at a minimum, the gson dependency is set to "provided".

The `LoadersManager` will check if Google's Gson parser is available on
path before attempting to register the JSON parser. (I'm happy to change this
behavior if you feel there's a better way to do this)

Usage -

```json
{
  "server": {
    "http": {
      "port": 80,
      "hostname": "localhost"
    },
    "ssh": {
      "port": 22,
      "address": "127.0.0.1",
      "alive": {
        "interval": 60
      },
      "user": "admin"
    },
    "admins": ["bob", "alice"]
  }
}
```

```java
@Config.Sources({"classpath:org/aeonbits/owner/server.test.json"})
public static interface ServerConfig extends Config, Accessible {

    @key("server.http.port")
    int httpPort();

    @key("server.http.hostname")
    String httpHostname();

    @key("server.ssh.port")
    int sshPort();

    @key("server.ssh.address")
    String sshAddress();

    @key("server.ssh.alive.interval")
    int aliveInterval();

    @key("server.ssh.user")
    String sshUser();

    @key("server.admins")
    List<String> admins();
}
```
@ketan
Copy link
Author

ketan commented Dec 16, 2015

All well, the build failing is some container issue with travis ci (travis-ci/travis-ci#5227)

@lviggiano
Copy link
Collaborator

Thanks!
Il 16 dic 2015 14:51, "Ketan Padegaonkar" [email protected] ha
scritto:

All well, the build failing is some container issue with travis ci (
travis-ci/travis-ci#5227
travis-ci/travis-ci#5227)


Reply to this email directly or view it on GitHub
#144 (comment).

@lviggiano
Copy link
Collaborator

The new year it should be better!
Il 16 dic 2015 16:09, "[email protected]" [email protected]
ha scritto:

Thanks!
Il 16 dic 2015 14:51, "Ketan Padegaonkar" [email protected] ha
scritto:

All well, the build failing is some container issue with travis ci (
travis-ci/travis-ci#5227
travis-ci/travis-ci#5227)


Reply to this email directly or view it on GitHub
#144 (comment).

@lviggiano lviggiano closed this Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants