You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Setting a EncodedValueFactory fails if the EnumEncodedValue class is not within com.graphhopper.routing.ev package #2894
Describe the bug
I needed some time to understand that setting a EncodedValueFactory fails if the EnumEncodedValue class is not within com.graphhopper.routing.ev package.
Create a package com.test.publictransport with an EncodedValueFactory (I used GH7):
public class BusEncodedValueFactory extends DefaultEncodedValueFactory {
public BusEncodedValueFactory() {
super();
}
@Override
public EncodedValue create(String name, PMap properties) {
if (Bus.KEY.equals(name)) {
return new EnumEncodedValue<>(Bus.KEY, Bus.class);
} else {
return super.create(name, properties);
}
}
}
and a Bus Enum:
public enum Bus {
MISSING, YES, DESIGNATED, DESTINATION, NO;
public static final String KEY = "bus";
public static EnumEncodedValue<Bus> create() {
return new EnumEncodedValue<>(Bus.KEY, Bus.class);
}
@Override
public String toString() {
return Helper.toLowerCase(super.toString());
}
public static Bus find(String name) {
if (name == null)
return MISSING;
try {
return Bus.valueOf(Helper.toUpperCase(name));
} catch (IllegalArgumentException ex) {
return MISSING;
}
}
}
If you set a BusEncodedValueFactory instance via hopper.setEncodedValueFactory you should get the following error:
java.lang.IllegalStateException: Could not deserialize encoded value: {"className":"com.graphhopper.routing.ev.EnumEncodedValue","name":"bus","bits":3,"min_storable_value":0,"max_storable_value":7,"max_value":4,"negate_reverse_direction":false,"store_two_directions":false,"fwd_data_index":2,"bwd_data_index":0,"fwd_shift":8,"bwd_shift":-1,"fwd_mask":1792,"bwd_mask":0,"enum_type":"com.graphhopper.routing.ev.Bus"}, error: Cannot construct instance of java.lang.Class, problem: com.graphhopper.routing.ev.Bus
Expected behavior
the factory should be loaded correctly OR
it should be documented e.g. in setEncodedValueFactory that you have to place the enums into com.graphhopper.routing.ev OR
give the user the possibility to specify another location for Janino imports
Activity