Coder Social home page Coder Social logo

java.lang.NullPointerException at de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer.getTerms(JacksonHydraSerializer.java:252) about hydra-java HOT 5 CLOSED

dschulten avatar dschulten commented on August 15, 2024
java.lang.NullPointerException at de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer.getTerms(JacksonHydraSerializer.java:252)

from hydra-java.

Comments (5)

dschulten avatar dschulten commented on August 15, 2024

I tried to reproduce it by making classes from the code above, but was unable to.
The problem seems related to enums somehow. Could you please tell me which of the dummy classes below is an enum in your model, or maybe which of these classes contain enums in turn, maybe as inherited members?
How do you initialize your Product? I tried to make OptionType an enum and wrote this test, which unfortunately succeeds:

    @Test
    public void convertsClassWithoutTerms() throws IOException {
        final Product product = new Product();
        product.addOptionType(OptionType.BAR);
        mapper.writeValue(w, product);
        assertEquals("{\"@context\":{\"@vocab\":\"http://schema.org/\"," +
                        "\"inventoryOnHand\":\"http://www.soluvas.org/commerceplug/1.0#inventoryOnHand\"}," +
                        "\"@type\":\"Product\"," +
                        "\"optionTypes\":[\"BAR\"]}",
                w.toString());
    }

Dummy classes I created:

    public class Action {}
    public class ImageObject {}

    public interface IThing {
        void setThingId(String id);
        List<String> getAdditionalTypes();
        String getAlternateName();
        String getDescription();
        ImageObject getImage();
        String getName();
        Action getPotentialAction();
        String getSameAs();
        String getUrl();
     }
     public interface IProduct {
        OrganizationOrBrand getBrand();
        void setBrand(OrganizationOrBrand brand);
        Organization getManufacturer();
        void setManufacturer(Organization manufacturer);
        String getSku();
        void setSku(String sku);
        String getBarcode();
        void setBarcode(String barcode);
        CurrencyUnit getPriceCurrency();
        void setPriceCurrency(CurrencyUnit currency);
        BigDecimal getPrice();
        void setPrice(BigDecimal price);
        DecimalMeasure<Mass> getWeight();
        void setWeight(DecimalMeasure<Mass> weight);
        DecimalMeasure<Length> getDepth();
        void setDepth(DecimalMeasure<Length> depth);
        DecimalMeasure<Length> getWidth();
        void setWidth(DecimalMeasure<Length> width);
        DecimalMeasure<Length> getHeight();
        void setHeight(DecimalMeasure<Length> height);
        IColor getColor();
        void setColor(IColor color);
        BigDecimal getProductionCost();
        void setProductionCost(BigDecimal productionCost);
        DecimalMeasure<Quantity> getInventoryLevel();
        void setInventoryLevel(DecimalMeasure<Quantity> inventoryLevel);
        DecimalMeasure<Quantity> getInventoryOnHand();
        void setInventoryOnHand(DecimalMeasure<Quantity> inventoryOnHand);
        List<OptionType> getOptionTypes();
        List<Product> getVariants();
        String getSerialNumber();
        void setSerialNumber(String serialNumber);
        List<PropertyValue<?>> getAdditionalProperties();
    }

    public class OrganizationOrBrand {}
    public class Organization {}
    public class CurrencyUnit {}
    public class Mass {}
    public class Length {}
    public class DecimalMeasure<T> {}
    public class IColor {}
    public class InventoryManagement {}
    public class InventoryPolicy {}
    public class Quantity {}
    public enum OptionType { FOO, BAR }
    public class PropertyValue<T> {}

from hydra-java.

dschulten avatar dschulten commented on August 15, 2024

I was able to reproduce this now, in combination with #7. No need to give more details at the moment.

from hydra-java.

dschulten avatar dschulten commented on August 15, 2024

Is it possible that in your test case the availability in Offer is null? That is the reason why my test case fails now, after solving the accessibility problem. When I use setAvailability to assign a value, the test runs through.
The serializer should of course ignore null values for enum members and not throw an exception.

from hydra-java.

ceefour avatar ceefour commented on August 15, 2024

Yes, uninitialized enums are null by default. These are part of current work developing CommercePlug API which uses Hydra (and this project hydra-java in order to render). Thanks for developing this library @dschulten :)

from hydra-java.

dschulten avatar dschulten commented on August 15, 2024

Solved in 0.2.0-SNAPSHOT

from hydra-java.

Related Issues (20)

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.