Coder Social home page Coder Social logo

whimtrip / jwht-htmltopojo Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 5.0 94 KB

Fully Featured, highly pluggable and customizable Java Html to Pojo converter.

License: MIT License

Java 100.00%
java html-parse html-parsing pojo reflection scrapper annotations framework

jwht-htmltopojo's People

Contributors

louis-wht avatar louissdev avatar scheshire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jwht-htmltopojo's Issues

Parsing integer format with locale

I tried to parse an integer value, that had a comma delimiter, like '1,234' and faced a problem with conversion with locale.

fr.whimtrip.ext.jwhtscrapper.exception.ModelBindingException: Scrap failed with exception Cannot parse field fiveStarsCount.class com.service.parser.pojo.ProductPojo with value 1,626 and locale: us.
	at fr.whimtrip.ext.jwhthtmltopojo.adapter.AbstractHtmlFieldImpl.instanceForNode(AbstractHtmlFieldImpl.java:201) ~[whimtrip-ext-htmltopojo-1.0.2.jar:na]

So, we need to respect locale while conversion number values, because currently an example like this

@Selector(
            value = ".example ",
            locale = 'US',
            returnDefValueOnThrow = false
    )
    public Integer fiveStarsCount;

can't be correctly casted. To use locale during number conversion we need to use method like this
Number number = NumberFormat.getIntegerInstance(Locale.US).parse('123,45');

This is default realiztaion of conversion at castValue in HtmlToPojoUtils


 if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
            if(value.equals(Selector.NO_VALUE))
                return (U) DEFAULT_NOT_FOUND_INTEGER;
            return (U) Integer.valueOf(value);
        }

My question is - can we solve this problem without using custom deserializer? Because currently this problem is in each of hundreds of Integer fields

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.