I am using JsonSchema2Pojo for converting json to Model objects.
It creates Model objects as expecetd. But, I need the annotation #JsonIgnoreProperties(ignoreUnknown = true) as well. There is no way to have this annotation with this JsonSchema2Pojo. But, looks like it supports with the property includeAdditionalProperties. Even after setting this, I dont see additionalPropertiesMap in the generated class. Is there anythign missing here?
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<sourceDirectory>${project.parent.basedir}/app-service/src/main/resources/schema</sourceDirectory>
<targetPackage>com.xyz.test.dto</targetPackage>
<annotationStyle>jackson2</annotationStyle>
<generateBuilders>true</generateBuilders>
<useCommonsLang3>true</useCommonsLang3>
<useLongIntegers>false</useLongIntegers>
<includeJsr303Annotations>true</includeJsr303Annotations>
<includeAdditionalProperties>false</includeAdditionalProperties>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
It can be done by using a custom annotator.
Sample implementation and usage is available here.
https://github.com/thewizardofjoz/jsonschema2pojo-ignoreunknown-annotator
https://github.com/thewizardofjoz/jsonschema2pojo-example
Related
I am using Zodiac FX openflow switches controlled by ODL on a MPLS network and
I am trying to push 2 stacked MPLS labels on a single packet(MPLS tunnel) with this flow:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow
xmlns="urn:opendaylight:flow:inventory">
<flow-name>POP Z2</flow-name>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<pop-mpls-action>
<ethernet-type> 8847</ethernet-type>
</pop-mpls-action>
<order>0</order>
</action>
<action>
<pop-mpls-action>
<ethernet-type>2048</ethernet-type>
</pop-mpls-action>
<order>1</order>
</action>
<action>
<output-action>
<output-node-connector>2</output-node-connector>
<max-length>60</max-length>
</output-action>
<order>2</order>
</action>
</apply-actions>
</instruction>
</instructions>
<id>126</id>
<strict>false</strict>
<match>
<in-port>1</in-port>
</match>
<idle-timeout>0</idle-timeout>
<cookie>401</cookie>
<cookie_mask>255</cookie_mask>
<installHw>false</installHw>
<hard-timeout>0</hard-timeout>
<priority>200</priority>
<table_id>0</table_id>
But ODL donĀ“t move the flow to the operational datastore.
I have tried the same flow but with only one push action and it remove the first MPLS tag.
Is ODL limited to push only one MPLS label? What can I do?
Operational datastore is populated with what's actually programmed into the switch, it goes config--->switch--->operational. with various ODL components doing various things (OF plugin, Statsmgr, fwdrulesmgr..) it can be failing at any of theses points. you can look at karaf log (set DEBUG) to see whats going on from the controller internals prospective, tcpdump ofchan to see what the controller is trying to push and look at the switch flows/log to see what gets programmed.
I have been messing with my logback coloring and Im wondering if I can change the highlighting colors. Right now I have this
Which is ok, but I would like to make info blue, warnings yellow and errors non-bold red or something along those lines. Is that possible? Also, is it possible to select different colors for the logger name highlighting? For instance, if I wanted com.blah to be cyan and org.apache logger magenta or something else? My current pattern is
<Pattern>%d{HH:mm:ss.SSS} %highlight(%-5level) [%thread] %cyan(%logger{36}) - %highlight(%msg%n)</Pattern>
This is a Scala project with SBT and I use logback for logging if that makes a difference.
Yes, judging from the Spring ColorConverter this should be possible with a bit of custom code. See the default Spring logback configuration.
For coloring JSON output with Logback Logstash, I've written (shameless plug) this project in which the same type of functionality can be added.
the bellow works for me
Java Code
package com.acme.logback;
public class MyCustomHighlighting extends ForegroundCompositeConverterBase<ILoggingEvent> {
#Override
protected String getForegroundColorCode(ILoggingEvent event) {
Level level = event.getLevel();
switch (level.toInt()) {
case Level.ERROR_INT:
return ANSIConstants.BOLD + ANSIConstants.RED_FG; // same as default color scheme
case Level.WARN_INT:
return ANSIConstants.RED_FG;// same as default color scheme
case Level.INFO_INT:
return ANSIConstants.CYAN_FG; // use CYAN instead of BLUE
default:
return ANSIConstants.DEFAULT_FG;
}
}
}
Logback.xml
<configuration>
<!-- custom coloring conversion -->
<conversionRule conversionWord="myCustomHighlighting" converterClass="com.acme.logback.MyCustomHighlighting" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
<pattern>[%thread] %myCustomHighlighting(%-5level) %logger{15} - %myCustomHighlighting(%msg) %n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
I'm building a webshop with just 2 simple products. (ID 1 and ID 2)
When a customer does a purchase, he receives a confirmation email with order info.
Also, the store where he wants to pick up the products receives an email with order info.
Now I want to build in an extra function:
An extra email with order info needs to be send to my email when a customer purchases ten or more of product with ID 1 or one or more of product with ID 2.
I am completely new to Magento and where to find the correct files to customize. So I hope someone can help me getting this to work! :)
You will need to use an observer for this
/app/etc/modules/Yournamaspace_Orderhook.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamaspace_Orderhook>
<active>true</active>
<codePool>community</codePool>
</Yournamaspace_Orderhook>
</modules>
</config>
/app/code/community/Yournamaspace/Orderhook/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamaspace_Orderhook>
<version>1.0</version>
</Yournamaspace_Orderhook>
</modules>
<global>
<models>
<orderhook>
<class>Yournamaspace_Orderhook_Model</class>
</orderhook>
</models>
<events>
<sales_order_place_after>
<observers>
<auto_email_order>
<type>singleton</type>
<class>orderhook/observer</class>
<method>implementOrderEmail</method>
</auto_email_order>
</observers>
</sales_order_place_after>
</events>
</global>
Create observer file
app/code/community/Yournamaspace/Orderhook/Model/Observer.php
class Yournamaspace_Orderhook_Model_Observer
{
public function implementOrderStatus($event)
{
// implement your code here for email order to speacific email address with your template
$order = $event->getOrder();
return $this;
}
}
hope this will sure help you.
I have a web.config file in which I need to either insert the <configSections /> element or manipulate children of that node if it already exists.
If it already exists I don't want to insert it again (obviously, as it is only allowed to exist once).
Normally, that would not be a problem, however:
If this element is in a configuration file, it must be the first child element of the element.
Source: MSDN.
So if I use xdt:Transform="InsertIfMissing" the <configSections /> element will always be inserted after any existing child elements (and there are always some), violating the above restriction of it having to be the first child element of <configuration />
I attempted to make this work in the following way:
<configSections
xdt:Transform="InsertBefore(/configuration/*[1])"
xdt:Locator="Condition(not(.))" />
Which works perfect, if the <configSections /> element doesn't already exist. However, the condition I've specified seems to be ignored.
In fact, I've tried a few conditions like:
Condition(not(/configuration[configSections]))
Condition(/configuration[configSections] = false())
Condition(not(/configuration/configSections))
Condition(/configuration/configSections = false())
Finally, out of desperation, I tried:
Condition(true() = false())
It still inserted the <configSections /> element.
It is important to note that I'm trying to include this in a NuGet package, so I will be unable to use a custom transform (like the one AppHarbor uses).
Is there any other clever way to get my element in the right place only if it doesn't yet exist?
To test this out, use AppHarbors config transform tester. Replace the Web.config with the following:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="initialSection" />
</configSections>
</configuration>
And Web.Debug.config with the following:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections
xdt:Transform="InsertBefore(/configuration/*[1])"
xdt:Locator="Condition(true() = false())" />
<configSections>
<section name="mySection" xdt:Transform="Insert" />
</configSections>
</configuration>
The result will show two <configSections /> elements, the one containing "mySection" being the first, as specified in the InsertBefore Transform.
Why was the Locator Condition not taken into account?
So after facing the same issue, I came up with a solution. It's not pretty nor elegant, but it works. (At least on my machine)
I just split the logic into 3 different statements. First, I add an empty configSections at the correct position (first). Then I insert the new config to the last configSections, which would be the new one if it is the only one, or a previously existing one otherwise.
Lastly I remove any empty configSections elemnt which might exist. I'm using RemoveAll for no good reason, you should probably use Remove.
The overall code looks like so:
<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />
<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
<section name="initialSection" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</configSections>
<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
The question which still remains unanswered is why Locator conditions are not taken into account for InsertBefore. Or why I can't handle an empty match set for InsertBefore, because that would allowed me to do fun things such as
//configuration/*[position()=1 and not(local-name()='configSections')]
Which to be honest is a much clearer way of doing what I want to achieve.
My powershell code actually reads data from an XML and stores the specific data to a csv file.
The XML file somewhat looks like below:
<?xml version="1.0" encoding="utf-8"?>
<Report Version="10.0">
<Targets>
<Target Name="\\bin\testBusiness.dll">
<Modules>
<Module Name="testing.dll" AssemblyVersion="1.0.1003.312" FileVersion="1.0.0.0">
<Metrics>
<Metric Name="Maintainability" Value="78" />
</Metrics>
</Module>
</Modules>
</Target>
</Targets>
</Report>
I need to extract only the "testing.dll" from the above XML code. The code I am using to do so is as below:
$testDLL = [regex]::matches($xmlfile[5], '<mod name=".*" ')[0].value -replace '<mod name="(.*)" ','$1'
#the above code line gets even the AssemblyVersion
$testAssembver = [regex]::matches($xmlfile[5], 'AssemblyVersion=".*" ')[0].value -replace 'AssemblyVersion=".*" ','$1'
I don't need AssemblyVersion to be concatenated to the "testing.dll (mod name in xml)" from the XML code.
Currently I get something like:
testing.dll" AssemblyVersion=1.0.1000.112"
I just need testing.dll, everything thereafter should be ommitted.
Please help.
Thanks,
Ashish
I don't think that regular expression is the best way to parse XML. Perhaps ou'd better use XMLDocument.
Using a better XML document :
<Dumy>
<Report Version="10.0"></Report>
<Goals>
<Name>"\\somepath\path.dll"</Name>
<Mods>
<Mod Name="testing.dll" AssemblyVersion="1.0.1000.112" FileVersion="1.0.0.1"></Mod>
</Mods>
</Goals>
</Dumy>
You can find your data like this :
$data = [XML](Get-Content "C:\temp\test.xml")
$data.Dumy.Goals.Mods.Mod.Name
Use XML as correctly suggested by JPBlanc. Then use XPath. Example, to extract the wanted value:
$data.selectnodes("//Modules/Module/#Name")