List of usage examples for com.fasterxml.jackson.databind.type TypeFactory constructMapType
public MapType constructMapType(Class<? extends Map> paramClass, Class<?> paramClass1, Class<?> paramClass2)
From source file:com.tikinou.schedulesdirect.core.jackson.converters.HeadendResultConverter.java
/** * Method that can be used to find out actual input (source) type; this * usually can be determined from type parameters, but may need * to be implemented differently from programmatically defined * converters (which can not change static type parameter bindings). * * @param typeFactory/* w w w.j av a 2 s. c om*/ * @since 2.2 */ @Override public JavaType getInputType(TypeFactory typeFactory) { return typeFactory.constructMapType(HashMap.class, String.class, Headend.class); }
From source file:org.ebayopensource.common.util.ParametersDeserializer.java
/** * We need to implement this method to properly find things to delegate * to: it can not be done earlier since delegated deserializers almost * certainly require access to this instance (at least "List" and "Map" ones) *///from w w w . j av a 2 s .com @Override public void resolve(DeserializationContext ctxt) throws JsonMappingException { JavaType obType = ctxt.constructType(Object.class); JavaType stringType = ctxt.constructType(String.class); TypeFactory tf = ctxt.getTypeFactory(); _mapDeserializer = _findCustomDeser(ctxt, tf.constructMapType(Map.class, stringType, obType)); }
From source file:com.aba.industry.manufacturing.impl.ManufacturingCalculatorImplUnitTests.java
@Test public void testSleipnirBuildCosts() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); InputStream bpDetailsIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-BlueprintDetails.json"); InputStream costIndexesIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-CostIndexes.json"); InputStream itemCostIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-ItemCosts.json"); TypeFactory typeFactory = mapper.getTypeFactory(); MapType mapType = typeFactory.constructMapType(HashMap.class, Integer.class, ItemCost.class); Map<Integer, ItemCost> itemCosts = mapper.readValue(itemCostIS, mapType); SystemCostIndexes costIndexes = mapper.readValue(costIndexesIS, SystemCostIndexes.class); BlueprintData bpData = mapper.readValue(bpDetailsIS, BlueprintData.class); IndustrySkillConfiguration industrySkills = new IndustrySkillConfiguration(); industrySkills.setAdvancedIndustrySkillLevel(5); industrySkills.setIndustrySkillLevel(5); industrySkills.setPreference(ConfigurationType.EXCEPTIONAL); for (ActivityMaterialWithCost am : bpData.getActivityMaterials() .get(IndustryActivities.MANUFACTURING.getActivityId())) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell());//from w w w . j a v a2s . co m am.setAdjustedCost(ic.getAdjusted()); } BuildCalculationResult result = calc.calculateBuildCost(costIndexes, 1d, bpData, 2, 4, industrySkills); Assert.assertEquals(312429715.96, result.getMaterialCost(), 0.01); Assert.assertEquals(20036519.59, result.getInstallationFees(), 0.01); Assert.assertEquals(2003651.95, result.getInstallationTax(), 0.01); Assert.assertEquals(result.getProductId(), 22444l); }
From source file:com.aba.industry.invention.impl.InventionCalculatorImplUnitTests.java
@Test public void testSleipnirWithNullDecryptor() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); InputStream bpDetailsIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-BlueprintDetails.json"); InputStream costIndexesIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-CostIndexes.json"); InputStream itemCostIS = InventionCalculatorImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-ItemCosts.json"); TypeFactory typeFactory = mapper.getTypeFactory(); MapType mapType = typeFactory.constructMapType(HashMap.class, Integer.class, ItemCost.class); Map<Integer, ItemCost> itemCosts = mapper.readValue(itemCostIS, mapType); SystemCostIndexes costIndexes = mapper.readValue(costIndexesIS, SystemCostIndexes.class); BlueprintData bpData = mapper.readValue(bpDetailsIS, BlueprintData.class); Decryptor decryptor = null;//from ww w. j ava 2s . co m InventionSkillConfiguration skillConfiguration = new InventionSkillConfiguration(); skillConfiguration.setDatacoreOneSkillLevel(3); skillConfiguration.setDatacoreTwoSkillLevel(3); skillConfiguration.setEncryptionSkillLevel(4); for (ActivityMaterialWithCost am : bpData.getActivityMaterials() .get(IndustryActivities.INVENTION.getActivityId())) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell()); am.setAdjustedCost(ic.getAdjusted()); } for (ActivityMaterialWithCost am : bpData.getActivityMaterials() .get(IndustryActivities.MANUFACTURING.getActivityId())) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell()); am.setAdjustedCost(ic.getAdjusted()); } InventionCalculationResult result = calcImpl.calculateInventionCosts(costIndexes, 0.0d, bpData, decryptor, skillConfiguration); Assert.assertNotNull("Result should not be null", result); Assert.assertEquals(6808205.92, result.getCostPerSuccessfulInventionRun(), 0.01); }
From source file:io.syndesis.jsondb.dao.JsonDbDao.java
@Override public ListResult<T> fetchAll() { try {//from w w w .j a v a 2 s. c om // get the data out.. byte[] json = jsondb.getAsByteArray(getCollectionPath()); if (json != null && json.length > 0) { // Lets use jackson to parse the map of keys to our model instances ObjectMapper mapper = Json.mapper(); TypeFactory typeFactory = mapper.getTypeFactory(); MapType mapType = typeFactory.constructMapType(LinkedHashMap.class, String.class, getType()); LinkedHashMap<String, T> map = mapper.readValue(json, mapType); return ListResult.of(map.values()); } return ListResult.of(Collections.<T>emptyList()); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException | IOException e) { throw SyndesisServerException.launderThrowable(e); } }
From source file:com.aba.industry.service.impl.IndustryCalculationServiceImplUnitTests.java
@Before public void dataSetupBeforeTests() throws IOException { InputStream bpDetailsIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-BlueprintDetails.json"); InputStream costIndexesIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-CostIndexes.json"); InputStream itemCostIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-ItemCosts.json"); InputStream buildCalculationResultIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-Output.json"); TypeFactory typeFactory = mapper.getTypeFactory(); mapType = typeFactory.constructMapType(HashMap.class, Integer.class, ItemCost.class); itemCosts = mapper.readValue(itemCostIS, mapType); costIndexes = mapper.readValue(costIndexesIS, SystemCostIndexes.class); bpData = mapper.readValue(bpDetailsIS, BlueprintData.class); buildCalculationResult = mapper.readValue(buildCalculationResultIS, BuildCalculationResult.class); inventionSkills = new InventionSkillConfiguration(); inventionSkills.setDatacoreOneSkillLevel(3); inventionSkills.setDatacoreTwoSkillLevel(3); inventionSkills.setEncryptionSkillLevel(4); industrySkills = new IndustrySkillConfiguration(); industrySkills.setAdvancedIndustrySkillLevel(5); industrySkills.setIndustrySkillLevel(5); industrySkills.setPreference(ConfigurationType.EXCEPTIONAL); for (ActivityMaterialWithCost am : bpData.getActivityMaterials() .get(IndustryActivities.INVENTION.getActivityId())) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell());/*w w w . jav a2s .co m*/ am.setAdjustedCost(ic.getAdjusted()); } for (ActivityMaterialWithCost am : bpData.getActivityMaterials() .get(IndustryActivities.MANUFACTURING.getActivityId())) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell()); am.setAdjustedCost(ic.getAdjusted()); } inventionCalculationResult = new InventionCalculationResult(); inventionCalculationResult.setSeconds(2000l); inventionCalculationResult.setResultingME(2); inventionCalculationResult.setResultingTE(4); jitaFreightDetails = new FreightDetails(); jitaFreightDetails.setCharge(13000000d); jitaFreightDetails.setJumps(15); amarrFreightDetails = new FreightDetails(); amarrFreightDetails.setCharge(6000000d); amarrFreightDetails.setJumps(9); }
From source file:com.kaaprotech.satu.jackson.SatuTypeModifier.java
@SuppressWarnings("unused") @Override//from w w w. ja v a 2 s .com public JavaType modifyType(JavaType type, Type jdkType, TypeBindings context, TypeFactory typeFactory) { final Class<?> raw = type.getRawClass(); if (ImmutableMap.class.isAssignableFrom(raw)) { JavaType keyType = type.containedType(0); JavaType contentType = type.containedType(1); if (keyType == null) { keyType = TypeFactory.unknownType(); } if (contentType == null) { contentType = TypeFactory.unknownType(); } return typeFactory.constructMapType(AbstractImmutableMap.class, keyType, contentType); } if (ImmutableSet.class.isAssignableFrom(raw)) { JavaType contentType = type.containedType(0); if (contentType == null) { contentType = TypeFactory.unknownType(); } return typeFactory.constructCollectionType(AbstractImmutableSet.class, contentType); } return type; }
From source file:com.aba.industry.service.impl.IndustryCalculationServiceImplAndCalculatorIntegrationTests.java
@Before public void dataSetupBeforeTests() throws IOException { InputStream bpDetailsIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-BlueprintDetails.json"); InputStream costIndexesIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-CostIndexes.json"); InputStream itemCostIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-ItemCosts.json"); InputStream buildCalculationResultIS = IndustryCalculationServiceImplUnitTests.class .getResourceAsStream("/testSleipnirWithNullDecryptor-Output.json"); TypeFactory typeFactory = mapper.getTypeFactory(); mapType = typeFactory.constructMapType(HashMap.class, Integer.class, ItemCost.class); itemCosts = mapper.readValue(itemCostIS, mapType); costIndexes = mapper.readValue(costIndexesIS, SystemCostIndexes.class); bpData = mapper.readValue(bpDetailsIS, BlueprintData.class); buildCalculationResult = mapper.readValue(buildCalculationResultIS, BuildCalculationResult.class); inventionSkills = new InventionSkillConfiguration(); inventionSkills.setDatacoreOneSkillLevel(3); inventionSkills.setDatacoreTwoSkillLevel(3); inventionSkills.setEncryptionSkillLevel(4); industrySkills = new IndustrySkillConfiguration(); industrySkills.setAdvancedIndustrySkillLevel(5); industrySkills.setIndustrySkillLevel(5); industrySkills.setPreference(ConfigurationType.EXCEPTIONAL); inventionMaterials = bpData.getActivityMaterials().get(IndustryActivities.INVENTION.getActivityId()); manufacturingMaterials = bpData.getActivityMaterials() .get(IndustryActivities.MANUFACTURING.getActivityId()); bpData.getActivityMaterials().clear(); bpData.getActivityMaterials().put(IndustryActivities.INVENTION.getActivityId(), new ArrayList<>()); bpData.getActivityMaterials().put(IndustryActivities.MANUFACTURING.getActivityId(), new ArrayList<>()); bpData.getBlueprintDetails().setPrecursorAdjustedPrice(null); for (ActivityMaterialWithCost am : inventionMaterials) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell());//ww w . jav a 2 s. c om am.setAdjustedCost(ic.getAdjusted()); ActivityMaterialWithCost amwcWithoutCosts = new ActivityMaterialWithCost(); } for (ActivityMaterialWithCost am : manufacturingMaterials) { ItemCost ic = itemCosts.get(am.getTypeId().intValue()); am.setCost(ic.getSell()); am.setAdjustedCost(ic.getAdjusted()); } inventionCalculationResult = new InventionCalculationResult(); inventionCalculationResult.setSeconds(2000l); jitaFreightDetails = new FreightDetails(); jitaFreightDetails.setCharge(13000000d); jitaFreightDetails.setJumps(15); amarrFreightDetails = new FreightDetails(); amarrFreightDetails.setCharge(6000000d); amarrFreightDetails.setJumps(9); }
From source file:com.almende.eve.test.agents.Test2Agent.java
/** * Test tf complex result./* ww w . j a v a 2 s .com*/ * * @param url * the url * @return the double * @throws Exception * the exception */ public Double testTFComplexResult(@Name("url") final String url) throws Exception { final TypeFactory tf = JOM.getTypeFactory(); final Map<String, List<Double>> res = send(URI.create(url), "complexResult", JOM.createObjectNode(), tf.constructMapType(HashMap.class, JOM.getTypeFactory().constructType(String.class), tf.constructCollectionType(List.class, Double.class))); return res.get("result").get(0); }