Giter VIP home page Giter VIP logo

holon-json's People

Contributors

axholo avatar fparoni avatar rrighi avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rrighi

holon-json's Issues

Getting class cast exception

I'm getting this error

Exception in thread "main" java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap cannot be cast to class com.holonplatform.core.property.PropertyBox (com.google.gson.internal.LinkedTreeMap and com.holonplatform.core.property.PropertyBox are in unnamed module of loader 'app')

and my code is

ListPathProperty<PropertyBox> DASAENTRIES = ListPathProperty.propertyBox("dasaEntries",DasaEntries.PROPERTIES);
    PropertySet<?> PROPERTIES = PropertySet.builderOf(DASAENTRIES)
            .build();
    PathProperty<PropertyBox> VIMSHOTTARIDASA = PathProperty.create("vimshottariDasa", PropertyBox.class)
            .withConfiguration(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE,PROPERTIES)

            ;


List<PropertyBox> dasaEntriesBox = propertyBox.getValue(VimshottariDasa.DASAENTRIES);

            for (PropertyBox pb : dasaEntriesBox) {
                System.out.println(pb);
            }

The error gets popup when I use this line

for (PropertyBox pb : dasaEntriesBox) {
                System.out.println(pb);
            }

Please help me to resolve this error.

Getting class cast exception for Jackson library

I'm trying to deserialize a json string which contains an Array.

 ListPathProperty<PropertyBox> DASAENTRIES = ListPathProperty.propertyBox("dasaEntries",DasaEntries.PROPERTIES);
    PropertySet<?> PROPERTIES = PropertySet.builderOf(DASAENTRIES)
            .build();
    PathProperty<PropertyBox> VIMSHOTTARIDASA = PathProperty.create("vimshottariDasa", PropertyBox.class)
            .withConfiguration(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE,PROPERTIES)

            ;

When trying to get this value from JSON string, I'm getting this exception

Exception in thread "main" java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class com.holonplatform.core.property.PropertyBox (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; com.holonplatform.core.property.PropertyBox is in unnamed module of loader 'app')
	at java.base/java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:999)
	at com.example.application.data.test.TestJson.lambda$getDasaEntries$2(TestJson.java:234)
	at java.base/java.util.Optional.ifPresent(Optional.java:176)
	at com.example.application.data.test.TestJson.lambda$getDasaEntries$3(TestJson.java:232)
	at java.base/java.util.Optional.ifPresent(Optional.java:176)
	at com.example.application.data.test.TestJson.getDasaEntries(TestJson.java:230)
	at com.example.application.data.test.TestJson.test(TestJson.java:152)
	at com.example.application.data.test.TestJson.main(TestJson.java:63)

This is where I'm getting the error

responseBox.getValueIfPresent(VimshottariDasa.VIMSHOTTARIDASA)
                .ifPresent(propertyBox -> {
                    propertyBox.getValueIfPresent(VimshottariDasa.DASAENTRIES)
                            .ifPresent(propertyBoxes -> {

                                for (PropertyBox box : propertyBoxes) { // error line
                                    
                                }

Looks there is some problem in casting and the below proves the same.

if (propertyBoxes.get(0) instanceof LinkedHashMap) {
                                    LinkedHashMap<?,?> map = (LinkedHashMap<?, ?>) propertyBoxes.get(0);
                                    map.entrySet()
                                            .stream()
                                            .forEach(entry -> {
                                                write(entry.getKey() +"\t" + entry.getValue());
                                            });
                                }else {
                                    write("not sure ");
                                }

Could you please check this ?

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.