Can FasterXML Jackson map mixed list child elements - jackson

Using the object mapper feature of FasterXML Jackson, I would like to parse this XML snippet:
<?xml version="1.0" encoding="utf-8"?>
<categories>
<category name="A">
<category name="B">
<setting type="Float">
<name>Bar</name>
</setting>
</category>
<setting type="Float">
<name>Foo</name>
</setting>
<category name="C">
<setting type="Float">
<name>Baz</name>
</setting>
</category>
</category>
</categories>
using the following Scala code:
case class Categories(#JacksonXmlProperty(localName = "category") categories: List[Category])
case class Category(name: String, #JacksonXmlProperty(localName = "category") categories: List[Category], #JacksonXmlProperty(localName = "setting") settings: List[Setting])
case class Setting(`type`: String, name: String)
val xmlMapper = new XmlMapper()
xmlMapper.registerModule(DefaultScalaModule)
xmlMapper.setDefaultUseWrapper(false)
val categories = xmlMapper.readValue(snippet, classOf[Categories])
println(categories)
// Categories(List(Category(A,List(Category(C,null,List(Setting(Float,Baz)))),List(Setting(Float,Foo)))))
I can see that Category B is missing from the result. If I change the order and move setting after the categories, it works as intended.
// Categories(List(Category(A,List(Category(B,null,List(Setting(Float,Bar))), Category(C,null,List(Setting(Float,Baz)))),List(Setting(Float,Foo)))))
<?xml version="1.0" encoding="utf-8"?>
<categories>
<category name="A">
<category name="B">
<setting type="Float">
<name>Bar</name>
</setting>
</category>
<category name="C">
<setting type="Float">
<name>Baz</name>
</setting>
</category>
<setting type="Float">
<name>Foo</name>
</setting>
</category>
</categories>
So it appears to be skipping elements if child list are mixed together. Is there a property I can set on the Mapper to fix this?

Related

web.config: How do I read an integer value?

I am making an api and I want to read from the web.config an integer value. I tried to do it like this:
<applicationSettings>
<HHH.Properties.Settings>
<setting name="loggerPath" serializeAs="String">
<value>Logs</value>
</setting>
<setting name="querytime" serializeAs="String">
<value>30</value>
</setting>
<setting name="windowstime" serializeAs="String">
<value>86400</value>
</setting>
<setting name="alarmarmingtime" serializeAs="String">
<value>300</value>
</setting>
</HHH.Properties.Settings>
</applicationSettings>
The value I want to read is the windowstime but it throws me an error.
In the serializeAs property I cannot choose "integer" for example because it is an enumerated one and it does not have this option. How should I do it?
I already resolved it. I used this:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="windowstime" value="86400"/>
</appSettings>

How to edit XML values using SQL queries?

I have an XML column UserDetails in a SQL Server database which has value like this:
<fleet>
<Setting name="city"/>
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email"/>
<setting value="user"/>
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone"/>
<setting value="technician"/>
</UserSettings>
</UserSettings>
</fleet>
I would to read from the db and add a new setting in
<UserSettings name="A2"> .
Can someone point me to what I should be doing?
You might use sql:variable() to introduce a value you've created externally. And you can use Xml.exist() to find XMLs which haven't got this new entry before:
DECLARE #myTbl TABLE(Descr VARCHAR(100),TheXml XML);
INSERT INTO #myTbl VALUES
(
'Setting "A3" doesn''t exist','<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>'
)
,(
'Setting "A3" exists already','<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
<UserSettings name="A3">
<setting type="3" name="A3 setting" />
<setting value="this exists already" />
</UserSettings>
</UserSettings>
</fleet>'
);
DECLARE #NewSetting XML=
N'<UserSettings name="A3">
<setting type="3" name="new A3" />
<setting value="new data" />
</UserSettings>';
UPDATE #myTbl
SET TheXml.modify('
insert sql:variable("#NewSetting")
as last into (/fleet/UserSettings)[1]')
WHERE TheXml.exist(N'/fleet/UserSettings[#name="details"]/UserSettings[#name="A3"]')=0;
SELECT * FROM #myTbl
SQL SERVER provides methods to modify XML data, and a language to do it (XML DML).
You need to use the modify method with an insert xml dml statement.
Here is the complete example:
Sample data:
DECLARE #myDoc xml;
SET #myDoc =
'<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>';
The statement:
SET #myDoc.modify('
insert <setting value="NEW SETTINGS" />
as first into (/fleet/UserSettings/UserSettings[#name="A2"])[1] ') ;
SELECT #myDoc;
Result:
<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting value="NEW SETTINGS" />
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>

Can RDP and attach debugger, MSVSMON.exe is running, but can't step-into cloud-environment web-role from my unit-test

I have a running WCF web role on Azure (not ASP.NET hosted!). I've seen many tutorials, tried many of them, and saw many SO questions - none of them seem to match my specific situation:
I'm able to connect with RDP
I see the MSVSMON.exe process in the host
I can attach to any process via VS2013-Update4 Server Explorer -> Instance -> Attach Debugger... (which process is the host, btw?)
The service works: tested with unit-test with the remote service reference
Disabled firewall - still no luck
I currently use Azure SDK 2.5
But when I try to Step Into from my unit-test, it says A remote operation is taking longer than expected and then: Unable to automatically step into the server. Connecting to the server machine '*.cloudapp.net' failed. The Microsoft Visual Studio Remote Debugging Monitor (MSVSMON.EXE) does not appear to be running on the remote computer. This may be because a firewall is preventing communication to the remote computer. Please see Help for assistance on configuring remote debugging.
What am I missing?
The csdef file:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyServiceWebRole.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-06.2.4">
<WebRole name="MyServiceWebRole" vmsize="Small">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<ConfigurationSettings>
<Setting name="Variable_1" />
<!-- ... -->
<Setting name="Variable_N" />
</ConfigurationSettings>
<Imports>
<Import moduleName="RemoteAccess" />
<Import moduleName="RemoteForwarder" />
</Imports>
</WebRole>
</ServiceDefinition>
The Cloud.cscfg file:
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyServiceWebRole.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-06.2.4">
<Role name="MyServiceWebRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="***" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" value="***" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" value="2016-10-01T23:59:59.0000000+03:00" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
<Setting name="Variable_1" value="Variable_1_Value=" />
<!-- ... -->
<Setting name="Variable_N" value="Variable_N_Value" />
</ConfigurationSettings>
<Certificates>
<Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="***" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
</ServiceConfiguration>

Issue with web service migration Enterprise library version 2 to 5

I have upgraded my web service project from vs 2005 to 2012. My webservice uses a project to log status in event viewer, which inturn uses enterprise library 2.0. Now that i have upgraded, i changed all my configs and dlls to newer version but while debugging i get this following exception.
{"Activation error occurred while trying to get instance of type LogWriter, key """}
InnerException:
{"Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
"}
StackTrace :
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
Could you please help me out with this, as i ve been working on this issue for 3 days now with no luck.
app.config:
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<section name="EnService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
</sectionGroup>
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="EnService" formatter="Text Formatter" log="MPASLog"
machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<applicationSettings>
<EnService.My.MySettings>
<setting name="CONST_PRINT_LOG" serializeAs="String">
<value>1</value>
</setting>
<setting name="CONST_JOB_STATUS_SUCCESS" serializeAs="String">
<value>1</value>
</setting>
<setting name="CONST_WEB_SERVICE_TIME_OUT" serializeAs="String">
<value>10800000</value>
</setting>
<setting name="Seperater" serializeAs="String">
<value>.</value>
</setting>
<setting name="EnService_EnServiceWebReference_EnServiceService" serializeAs="String">
<value>http://localhost/EnServiceService.asmx</value>
</setting>
<setting name="PrintFolder" serializeAs="String">
<value>C:\Jobs\PrintDocuments\</value>
</setting>
<setting name="ResultLocation" serializeAs="String">
<value>C:\Jobs\EnService\Result</value>
</setting>
<setting name="ArchiveFilePrefix" serializeAs="String">
<value>EnService_Report_</value>
</setting>
<setting name="ExceptionArchiveFilePrefix" serializeAs="String">
<value>EnService_Exception_Report_</value>
</setting>
<setting name="CONST_PRINT_REPORT" serializeAs="String">
<value>X</value>
</setting>
<setting name="ReportArchiveLocation" serializeAs="String">
<value>C:\Jobs\EnService\OUT</value>
</setting>
<setting name="CommonWebServiceURL" serializeAs="String">
<value>http://localhost/WebService/Service.asmx</value>
</setting>
</EnService.My.MySettings>
</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Appreciate your help,
Vinay
I was using logger.write() in my application
When i added
" Logger.SetLogWriter(New LogWriterFactory().Create(), False) "`
My application worked fine.

XmlMassUpdate - Replace Value Node

I'm trying to use XmlMassUpdate to update my config files based on build Version type. There seems to be no documentation on how to update the new app.config (vs2008) settings formats anywhere.
This is the config section:
<applicationSettings>
<CTC.Mica.ClientService.Properties.Settings>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService"
serializeAs="String">
<value>URL</value>
</setting>
</CTC.Mica.ClientService.Properties.Settings>
</applicationSettings>
And i am trying to update the URL value from this file:
<Debug>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>DEVURL</value>
</setting>
</Debug>
<Test>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>TESTURL</value>
</setting>
</Test>
<Release>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>LIVEURL</value>
</setting>
</Release>
Running the script, i can replace either the "name" or the "serializeAs" attributes, but not the value node.
How would i go about replacing the value node?
Regards
Tris
The following scripts work fine for me (running on 1.3.0.471 which might be a nightly build):
build.proj
<Project DefaultTargets="Run" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.targets" />
<Target Name="Run">
<Delete Condition="Exists('output.xml')" Files="output.xml"/>
<XmlMassUpdate
ContentFile="input.xml"
ContentRoot="/test"
SubstitutionsFile="subs.xml"
SubstitutionsRoot="/substitutions/release"
MergedFile="output.xml"
/>
</Target>
</Project>
input.xml
<test>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>URL</value>
</setting>
</test>
subs.xml
<substitutions xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<release>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
<value>LIVEURL</value>
</setting>
</release>
</substitutions>
output.xml (generated by build)
<test>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
<value>LIVEURL</value>
</setting>
</test>