Giter Club home page Giter Club logo

jtoml's Introduction

Hey, I'm Alexandre ๐Ÿ‘‹

But everybody calls me Alex.

I'm a Software Engineer from Metz/France ๐Ÿ‡ซ๐Ÿ‡ท and working as a Tech Lead & Software Craftsman in Luxembourg ๐Ÿ‡ฑ๐Ÿ‡บ.

In my spare time I like to code ๐Ÿ‘จโ€๐Ÿ’ป in various languages including Java, Kotlin, Clojure/ClojureScript โค๏ธ, Javascript, Go, Python, Ruby, OCaml, and a few other. I'm interested in both backend and frontend having practiced them extensively.

From APIs to mobile, through cloud and databases, preferrably using a functional programming language.

I wrote Practical Vavr.

Beside coding ๐Ÿ‘จโ€๐Ÿ’ป, I'm passionate about travels ๐ŸŒ„, photography ๐Ÿ“ท, football โšฝ, badminton ๐Ÿธ, music ๐ŸŽถ, movies ๐ŸŽฅ and guitars ๐ŸŽธ.

You can find me at grison.me and on Twitter

Cheers!

jtoml's People

Contributors

agrison avatar dependabot[bot] avatar jbman avatar mwanji avatar voho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jtoml's Issues

Support for arrays of tables

The TOML GitHub page has an example of arrays of tables (which may or may not be nested) that jtoml seems not to support. The example is:

foo = "bar"

[[fruit]]
  name = "apple"

  [[fruit.variety]]
    name = "red delicious"
  [[fruit.variety]]
    name = "granny smith"

[[fruit]]
  name = "banana"

  [[fruit.variety]]
    name = "plantain"

baz = "quux"

Note: I added the foo and baz sections to check that something was parsing.

When I try this example in jtoml, it returns nothing for the key "fruit".

File f = new File("fruit.toml");
Toml t = Toml.parse(f);
System.out.println(t.getString("foo")); // prints bar
System.out.println(t.getString("baz")); // prints null
Object object = t.get("fruit");
System.out.println(object);             // prints null

Request: jtoml should support this.

Note: I used version 1.1.0 for this test.

Also, notice that the getString("baz") returns null. If I put the baz="quux" at the top of the file, it returns "quux", so it looks like the jtoml parser just stops when it hits a part of the file it considers an error and stops parsing. This seems like a defect in the parser. In my view, it should throw an exception if the TOML file is invalid. Perhaps I should file another issue?

Can't parse single character keys

This does not work:
Toml t = Toml.parse("a = -3");โ€จ System.out.println(t.serialize());

but if the key is more than one char it works, like this:
Toml t = Toml.parse("ab = -3.1");โ€จ System.out.println(t.serialize());

Toml.parse throwing policy

That might be a stupid question, but from the source it seems that Toml.parse is only susceptible to throw a FileNotFoundException, not an IOException.

I understand that the later is more general than the former, but why not throwing the most precise kind?

This seems to need a good tidy up with the aid of an issue hinting IDE.

JetBrains "IntelliJ IDEA Community 2002.2" found plenty of legacy issues, even for Java 1.6 ...hmm...
I would ignore it's hints about Regex because they looked wrong to me.

I prefer no earlier than Java 1.8 now, so even more is possible with that.

The JavaDoc build step had HTML/Javadoc warning and errors, which stopped install...
e.g. > is a reserved character in HTML, so must be added as HTML entity >.

Started working on ANTLR

Hey, I just started to work on an ANTLR version of jtoml, mostly for educational purposes to learn ANTLR. It's my first hands-on with a grammar, so I expect to make a lot of dumb mistakes, but maybe you're interested in my current code: https://github.com/MoriTanosuke/jtoml/tree/antlr

I try to push the branch to github whenever I have a major change in the grammar or the application code.

Bug: getAs(Stringkey,Class<?>) returns NullPointerException for missing key, which is not helpful

Caused by: java.lang.NullPointerException
	at me.grison.jtoml.impl.Toml.get(Toml.java:184)
	at me.grison.jtoml.impl.Toml.get(Toml.java:262)
	at me.grison.jtoml.impl.Toml.getAs(Toml.java:241)

Exceptions should not be used for flow control, so if the key is missing, null should be returned.
I'll have to see if I can detect the absence of just the key, as a workaround for this bug, until it's fixed.

Adding a map to the Test Pojo foo will try to create [foo.bar.map], not [foo.map]

While trying to figure out some loops occuring, see other issue I found out that if you add a map to the Test Pojo the creation of the key is wrong.

public static class Foo {

    String stringKey;
    Long longKey;
    Double doubleKey;
    Boolean booleanKey;
    List<Object> listKey;
    Bar bar;
    Boolean awesome;
    Map<String, Integer> map = new HashMap<String, Integer>() {{
        put("one",1);
        put("two",2);
    }};

This will create a key with [foo.bar.map] instead of [foo.map]

Parse a File can fail deppending on text content

The parser will fail for a file with the following content.
title = "anything รฉ "

The problem is caused by the function Util.FileToString.read(File file) that does not support accented characters.

I fixed using the Apache CommonIO FileUtils.readFileToString but this function can solve the problem:

public static class FileToString {
        public static String read(File file)
          throws FileNotFoundException {
            String result = "";
            DataInputStream in = null;
            try {

            byte[] buffer = new byte[(int) file.length()];
            in = new DataInputStream(new FileInputStream(file));
            in.readFully(buffer);
            result = new String(buffer);
            } catch (IOException ex) {
                throw new FileNotFoundException(ex.getMessage());
            }
            return result;
        }
}

cheers

Serialization failed

# groovy
class Foo {
    private String name;

    public Foo(){}

    public String getName() {
        return name
    }

    public void setName(String name) {
        this.name = name
    }
}

Foo foo = new Foo()
foo.name = 'eiryu'
println Toml.serialize('root', foo)
.
.
.
.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.cachedClassRef.info.modifiedExpandos`.
    ... 1024 more
Caused by: java.lang.StackOverflowError
    at me.grison.jtoml.impl.SimpleTomlSerializer.serialize(SimpleTomlSerializer.java:101)
    ... 1021 more

TOML_SUPPORTED in Util is missing Integer.class

TOML_SUPPORTED should be:

    /**
     * List of types supported Natively by TOML + Map
     */
    static final Set<Class<?>> TOML_SUPPORTED = new HashSet<Class<?>>(Arrays.asList(Integer.class, Long.class, Double.class, //
            Calendar.class, Boolean.class, String.class, List.class, Map.class));

Passing a String into Toml.serialize("test",string) will cause a loop

If you pass a String directly into Toml.serialize with a root key it will cause a loop.

Here a test log.

20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [7]
[20:23:05] [INFO] [TCBase] [DEBUG] field [value]
[20:23:05] [INFO] [TCBase] [DEBUG] type [[C]
[20:23:05] [INFO] [TCBase] [DEBUG] value [[C@7cbc11d]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [0]
[20:23:05] [INFO] [TCBase] [DEBUG] field [hash]
[20:23:05] [INFO] [TCBase] [DEBUG] type [int]
[20:23:05] [INFO] [TCBase] [DEBUG] value [0]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value.hash]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [11]
[20:23:05] [INFO] [TCBase] [DEBUG] field [MIN_VALUE]
[20:23:05] [INFO] [TCBase] [DEBUG] type [int]
[20:23:05] [INFO] [TCBase] [DEBUG] value [-2147483648]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value.hash.MIN_VALUE]

Can't parse negative integers from tables

this does not work:
Toml t = Toml.parse("[a]\ncd = -3");โ€จ System.out.println(t.serialize());
but this does:
Toml t = Toml.parse("[a]\ncd = -3.1");โ€จ System.out.println(t.serialize());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.