Closed ceefour closed 9 years ago
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> {}
I was able to reproduce this now, in combination with #7. No need to give more details at the moment.
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.
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 :)
Solved in 0.2.0-SNAPSHOT
The NullPointerException should give an explanation what is expected.
The exception is thrown here:
With following models:
Product.java:
Thing.java:
Error: