@Override
    public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception {
        int originalDepth = context.getCurrentDepth();
        int targetDepth = originalDepth + 1;

        if (context.isStartOfDocument()) {
            targetDepth += 1;
        }

        String id = null;
        List<String> events = new ArrayList<String>();
        Filter filter = null;
        String functionArn = null;
        String invocationRole = null;

        while (true) {
            XMLEvent xmlEvent = context.nextEvent();
            if (xmlEvent.isEndDocument()) {
                return createLambdaConfig(id, events, functionArn, invocationRole, filter);
            }

            if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
                if (context.testExpression("Id", targetDepth)) {
                    id = StringStaxUnmarshaller.getInstance().unmarshall(context);
                } else if (context.testExpression("Event", targetDepth)) {
                    events.add(StringStaxUnmarshaller.getInstance().unmarshall(context));
                } else if (context.testExpression("Filter", targetDepth)) {
                    filter = FilterStaxUnmarshaller.getInstance().unmarshall(context);
                } else if (context.testExpression("CloudFunction", targetDepth)) {
                    functionArn = StringStaxUnmarshaller.getInstance().unmarshall(context);
                } else if (context.testExpression("InvocationRole", targetDepth)) {
                    invocationRole = StringStaxUnmarshaller.getInstance().unmarshall(context);
                }
            } else if (xmlEvent.isEndElement()) {
                if (context.getCurrentDepth() < originalDepth) {
                    return createLambdaConfig(id, events, functionArn, invocationRole, filter);
                }
            }
        }
    }
CloudFunctionConfiguration is a little different then Topic or Queue Configurations and thus
doesn't fit nicely as a subclass of {@link NotificationConfigurationStaxUnmarshaller}. A
CloudFunctionConfiguration element may be unmarshalled into two different classes based on
presence of the InvocationRole attribute. If InvocationRole is present we unmarshall into the
legacy {@link CloudFunctionConfiguration}, otherwise we unmarshall into
{@link LambdaConfiguration}.
aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/model/transform/LambdaConfigurationStaxUnmarshaller.java