Deserialize PrimaryKey (DynamoDB) with Jackson - jackson

An error is thrown when I'm trying to deserialize PrimaryKey (serialization goes well with Jackson).
I'm trying the following:
Myobject myObject =(Myobject) mapper.convertValue(obj.get("myObject"), MyObject.class);
with object:
public class MyObject {
private PrimaryKey primaryKey;
private String attributeName;
private String metaDataFieldName;
private long numRepeated;
And getting the error:
java.lang.IllegalArgumentException: (was java.lang.UnsupportedOperationException) (through reference chain: com.scanner.dynamodb.DynamoDBDataLink["primaryKey"]->com.amazonaws.services.dynamodbv2.document.PrimaryKey["componentNameSet"]->java.util.LinkedKeySet[0])
Thanks

Related

Out of Stack Space Error when setting Custom Object Parameter

I have a custom class module called Service with string parameters.
I instantiate the class by creating an object this_service like so:
Dim this_service As Service
Set this_service = New Service
Then I try to set a parameter to any string value like so:
this_service.Key = "HELLO"
When I run the macro I get the 28 Runtime Error, Out of Stack Space.
In my class module Service I have the following parameter definition and method calls:
Private pKey As String
Public Property Get Key() As String
Key = pKey
End Property
Public Property Let Key(Value As String)
Key = Value
End Property
I can't see any reason why I'd be getting this runtime error?
In Public Property Let it should be:
pKey = Value
Right now it calls the setter recursively (indefinitely).

Null reference exceptions on properties of a newly instantiated class? What's going on here?

I'm toying around with a 3rd party library and something has me absolutely puzzled.
When I instantiate this class, immediately all of the properties of the class throw exceptions before any more code even runs. Why is this happening? It's not just this TypedSegmentPWK class, it's all of the typedsegment classes.. of which there are many.
Simple instantiation fails
Imports OopFactory.X12.Parsing
Imports OopFactory.X12.Parsing.Model
Imports OopFactory.X12.Parsing.Model.Typed
....
Dim test As New TypedSegmentPWK
test.PWK04_EntityIdentifierCode = "blah"
Assigning a value to PWK04_EntityIdentifierCode or any other property of test fails with a null reference exception.
TypedSegmentPWK:
Namespace OopFactory.X12.Parsing.Model.Typed
Public Class TypedSegmentPWK
Inherits TypedSegment
Public Sub New()
Public Property PWK01_ReportTypeCode As String
Public Property PWK02_ReportTransmissionCode As String
Public Property PWK03_ReportCopiesNeeded As Integer?
Public Property PWK04_EntityIdentiferCodeEnum As EntityIdentifierCode
Public Property PWK04_EntityIdentifierCode As String
Public Property PWK05_IdentificationCodeQualifier As String
Public Property PWK05_IdentificationCodeQualifierEnum As IdentificationCodeQualifier
Public Property PWK06_IdentificationCode As String
Public Property PWK07_Description As String
Public Property PWK08_ActionsIndicated As String
Public Property PWK09_RequestCategoryCode As String
End Class
End Namespace
TypedSegment:
Namespace OopFactory.X12.Parsing.Model
Public MustInherit Class TypedSegment
Protected Sub New(segmentId As String)
Public Event Initialized As EventHandler
Public Event Initializing As EventHandler
Protected Overridable Sub OnInitialized(e As EventArgs)
Protected Overridable Sub OnInitializing(e As EventArgs)
End Class
End Namespace
Full source here: https://github.com/KeyMarkInc/OopFactory.X12
All the properties reference _segment defined in TypedSegment, e.g.
public string PWK04_EntityIdentifierCode
{
get { return _segment.GetElement(4); }
set { _segment.SetElement(4, value); }
}
However, the _segment variable is not initialized until TypedSegment.Initialize(Container parent, X12DelimiterSet delimiters) is called...
internal void Initialize(Container parent, X12DelimiterSet delimiters)
{
OnInitializing(new EventArgs());
_segment = new Segment(parent, delimiters, _segmentId);
OnInitialized(new EventArgs());
}
This is an internal method, so presumably something in this framework is supposed to call it, and not you as the user. So, I would guess the answer is that you are using the TypedSegmentPWK class incorrectly, although I don't know what the correct way is.

Entity Framework errors while saving base class if there is any inheritance

I am using EF 6.1. I have a model "Request" built from the wizard directly from my database. In my context file (EMContext.vb) I have
Public Overridable Property Requests As DbSet(Of Request)
When I type in
Dim db As New EMContext
Dim req As New Request()
With req
.RequestedBy = "bar"
.EventName = "Goo"
.RequestedOn = Now
.RequestStatusID = 1
End With
db.Requests.Add(req)
db.SaveChanges()
everything works exactly as expected. No problems. It saves.
However, if I add a class (anywhere in the app)
Class foo
Inherits Request
Public Property s As String
End Class
and then run the exact same code I get
{"An error occurred while updating the entries. See the inner exception for details."}
Looking at the inner exception:
{"Invalid column name 's'.
Invalid column name 'Discriminator'."}
Why in the heck is it even looking at the inherited class properties?
BTW, if I remove all the properties from the inherited class, I still get the Invalid Column 'Discriminator' error.
Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class
Usage:
Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...

Using VB.net Collection class via COM returns error: "Class doesn't support automation"

I have an existing VB.net class library which has a public property with a type of VB's Collection class. I'm exposing the class library as a COM-object to be able to use it in Progress.
When I access the Collection-property with an integer index (e.g. comObj.OutputCol.Item(1)) it works fine, but when I try to use the string indexer (e.g. comObj.OutputCol.Item("FirstCol")) I get the following error (from a VBScript I use for testing):
Error message: Class doesn't support automation
Error code: 800A01AE
Is it possible to use the string indexer in any way via COM?
Sample code, COM-object i VB.net:
<ComClass(TestClass.ClassId, TestClass.InterfaceId, TestClass.EventsId)>
Public Class TestClass
Public Const ClassId As String = "063CA388-9926-44EC-B3A6-856D5299C210"
Public Const InterfaceId As String = "094ECC57-4E84-423A-B20E-BD109AEDBC20"
Public Const EventsId As String = "038B18BD-54B4-42D3-B868-71F4C52345B0"
Private _sOutputCol As Collection = Nothing
Private Property sOutputCol() As Collection
Get
If _sOutputCol Is Nothing Then
_sOutputCol = New Collection()
End If
Return _sOutputCol
End Get
Set(ByVal Value As Collection)
_sOutputCol = Value
End Set
End Property
Public ReadOnly Property OutputCol() As Collection
Get
Return sOutputCol
End Get
End Property
Public Sub New()
sOutputCol.Add("First object", "FirstCol")
sOutputCol.Add(2, "SecondCol")
End Sub
End Class
Sample test-code in VBScript:
Set comObj = WScript.CreateObject("VbComTest.TestClass")
wscript.echo comObj.OutputCol.Item(1) ' Works
wscript.echo comObj.OutputCol.Item(CStr("FirstCol")) ' Gives the error
I have registred the dll with: >regasm "...path...\VbComTest.dll" /codebase
OK, the problem was that the indexer is overloaded and you shouldn't use that in COM-visible interfaces: https://msdn.microsoft.com/en-us/library/ms182197.aspx
Extract from the page about what happens to overloaded methods:
When overloaded methods are exposed to COM clients, only the first
method overload retains its name. Subsequent overloads are uniquely
renamed by appending to the name an underscore character '_' and an
integer that corresponds to the order of declaration of the overload.
For example, consider the following methods.
void SomeMethod(int valueOne); void SomeMethod(int valueOne, int
valueTwo, int valueThree); void SomeMethod(int valueOne, int
valueTwo);
These methods are exposed to COM clients as the following.
void SomeMethod(int valueOne); void SomeMethod_2(int valueOne,
int valueTwo, int valueThree); void SomeMethod_3(int valueOne, int
valueTwo);
Visual Basic 6 COM clients cannot implement interface methods by using
an underscore in the name.
So to use the string indexer I have to write:
wscript.echo comObj.OutputCol.Item_3("FirstCol")
(Item_2 takes an Object as parameter and will also work, if the documentation is correct).

vb.net json.net deserialization issue

I have an issue that is driving me nuts. I have a project to deserialize and process a json response:
[{"summary":[{"cardDate":"2013-08-06","cardId":46121,"contenderList":[1,2,3,4,5,7,8,10],"dateTime":"2013-08-06 10:36","marketList":["TOTE_WIN_PLACE","FORECAST","FORECAST_PLACE"],"raceId":465453,"raceNumber":2,"tote":"Australia","venue":"AU - Dog, Bendigo"}]
I have built classes to handle the response:
Public Class clsAXMeetList
Public Property summary() As clsAXRaceList()
End Class
Public Class clsAXRaceList
Public Property cardDate As String
Public Property cardID As Integer
Public Property [contenderList]() As clsAXContenderList()
Public Property dateTime As String
Public Property [marketList]() As clsAXMarketList()
Public Property raceID As String
Public Property raceNumber As Integer
Public Property tote As String
Public Property venue As String
End Class
Public Class clsAXContenderList
Public Property runners() As Integer
End Class
Public Class clsAXMarketList
Public Property [a] As String
Public Property [b] As String
Public Property [c] As String
End Class
but when the deserializer hits the first value in the contender list (1) it throws this error:
Error converting value 1 to type 'AsiaExchange.clsAXContenderList'. Path '[0].summary[0].contenderList[0]', line 1, position 71.
I have looked around and I cant find much help
The contenderList is an array of numbers, not objects. There is no conversion from numbers to arbitrary objects. You need to either change your contenderList property to an array of integers (Integer()) or provide a converter to your object. You will have to do the same for the marketList as well.