Skip to content

Commit

Permalink
Fixed Javadoc, and README
Browse files Browse the repository at this point in the history
  • Loading branch information
tajakobsen committed Aug 27, 2015
1 parent fd74e13 commit d3b52cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ To create a [Parser](src/main/java/com/nerdforge/unxml/parsers/Parser.java) you
Parsing parsing = ParsingFactory.getInstance().create();

// create parser that will output a Jackson ObjectNode
Parser parser = parsing.obj().attribute("resultKey", "//my-xpath").build();
Parser parser2 = parsing.obj("//my-root").attribute("id", "@id").build();
Parser<ObjectNode> parser = parsing.obj().attribute("resultKey", "//my-xpath").build();
Parser<ObjectNode> parser2 = parsing.obj("//my-root").attribute("id", "@id").build();

// create parser that will output a Jackson ArrayNode
Parser parser3 = parsing.arr(parsing.obj().attribute("id", "@id"));
Parser<ArrayNode> parser3 = parsing.arr(parsing.obj().attribute("id", "@id"));
```

## Example - Parsing an object
Expand All @@ -67,12 +67,12 @@ public class MyController {
Parsing parsing = ParsingFactory.getInstance().create();
Document document = parsing.xml().document(inputXmlString);

Parser parser = parsing.obj() // (1)
Parser<ObjectNode> parser = parsing.obj() // (1)
.attribute("id", "/root/id", parsing.with(Integer::parseInt)) // (2)
.attribute("title", "//title") // (3)
.build(); // (4)

JsonNode node = parser.apply(document); // (5)
ObjectNode node = parser.apply(document); // (5)
return node;
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ Since a [Parser](src/main/java/com/nerdforge/unxml/parsers/Parser.java) is a [fu

```java
Parsing parsing = ParsingFactory.getInstance(namespaces).create(); // (1)
Parser parser = ... // se below for examples
Parser parser = ... // se above for examples
Document document = parsing.xml().document(inputXmlString); // (2)

// Apply to an Optional
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ targetCompatibility = 1.8

archivesBaseName = "unxml"
group = 'com.nerdforge'
version = '0.7-SNAPSHOT'
version = '0.8'

repositories {
mavenLocal()
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/nerdforge/unxml/parsers/ArrayParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public ArrayNode apply(Node node) {

/**
* Returns the parsed result as a List of Objects of class A
* @return Result as a List of Objects
* @param valueType The type of class that should be instansiated in the list
* @param <A> The Class the ListParser will return a list of.
* @return Result as a List of Objects of class A
*/
public <A> ListParser<A> as(Class<A> valueType){
return this.<List<A>>andThen(jsonUtil.asList(valueType))::apply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public ObjectParser build(){
}

/**
* Returns some Json utility methods
* @return An instance of JsonUtil
* Uses Jackson to instansiate the ObjectNode as a Java Object of type A.
* @param valueType The type of class that should be instansiated
* @param <A> The Class the InstanceParser will return
* @return A parser that outputs an object of Class A.
*/
public <A> InstanceParser<A> as(Class<A> valueType) {
return build().<A>andThen(jsonUtil.as(valueType))::apply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testParseObject() {
.attribute("id", "/root/id", parsing.with(Integer::parseInt))
.attribute("title", "//title");

ObjectParser parser = builder.build();
Parser<ObjectNode> parser = builder.build();
JsonNode node = parser.apply(input);

assertThat(node.get("id").asInt()).isEqualTo(1);
Expand Down

0 comments on commit d3b52cf

Please sign in to comment.